mirror of
https://github.com/coredns/coredns.git
synced 2026-10-08 19:45:21 -04:00
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:
4
plugin/cache/cache.go
vendored
4
plugin/cache/cache.go
vendored
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user