mirror of
https://github.com/coredns/coredns.git
synced 2026-10-09 03:55: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:
18
plugin/cache/cache_test.go
vendored
18
plugin/cache/cache_test.go
vendored
@@ -1990,3 +1990,21 @@ func TestServeFromStaleCacheFetchVerifyTimeoutMetadataIsolation(t *testing.T) {
|
||||
t.Fatalf("background verifier mutated foreground metadata: %q", f())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCacheWriteMsgNilResponse(t *testing.T) {
|
||||
c := New()
|
||||
|
||||
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||
cw := &ResponseWriter{ResponseWriter: rec, Cache: c}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Fatalf("ResponseWriter.WriteMsg panicked on nil response: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
err := cw.WriteMsg(nil)
|
||||
if err == nil {
|
||||
t.Error("Expected error when passing nil response to WriteMsg, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user