plugin/cache: Prevents a nil pointer dereference panic in the cache prefetch (#8512)

* plugin/cache: Prevents a nil pointer dereference panic in the cache prefetch

This PR prevents a nil pointer dereference panic in the cache prefetch, by
adding nil guards

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Address comment

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

---------

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang
2026-09-03 01:11:33 -07:00
committed by GitHub
parent c942ca7c36
commit c2e309e2e4
2 changed files with 22 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package cache
import (
"encoding/binary"
"fmt"
"hash/fnv"
"net"
"strings"
@@ -413,6 +414,9 @@ func (w *ResponseWriter) Hijack() {
// WriteMsg implements the dns.ResponseWriter interface.
func (w *ResponseWriter) WriteMsg(res *dns.Msg) error {
if res == nil {
return fmt.Errorf("cache: response message is nil")
}
res = res.Copy()
w.lastItem = nil
mt := cacheResponseType(res, w.now().UTC())