mirror of
https://github.com/coredns/coredns.git
synced 2026-09-05 03:27:08 -04:00
plugin/minimal: Fixes a nil pointer dereference panic in minimal prefetch response processing (#8506)
* plugin/minimal: Fixes a nil pointer dereference panic in minimal prefetch response processing This PR fixes a nil pointer dereference panic in minimal prefetch response processing Signed-off-by: Yong Tang <yong.tang.github@outlook.com> * Fix lint 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:
@@ -26,6 +26,9 @@ func (m *minimalHandler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return rcode, err
|
return rcode, err
|
||||||
}
|
}
|
||||||
|
if nw.Msg == nil {
|
||||||
|
return rcode, nil
|
||||||
|
}
|
||||||
|
|
||||||
ty, _ := response.Typify(nw.Msg, time.Now().UTC())
|
ty, _ := response.Typify(nw.Msg, time.Now().UTC())
|
||||||
cl := response.Classify(ty)
|
cl := response.Classify(ty)
|
||||||
|
|||||||
@@ -151,3 +151,20 @@ func TestMinimizeResponse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMinimizeResponseNilMsgPanic(t *testing.T) {
|
||||||
|
nilMsgHandler := plugin.HandlerFunc(func(_ context.Context, w dns.ResponseWriter, _ *dns.Msg) (int, error) {
|
||||||
|
w.WriteMsg(nil)
|
||||||
|
return 0, nil
|
||||||
|
})
|
||||||
|
|
||||||
|
o := minimalHandler{Next: nilMsgHandler}
|
||||||
|
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||||
|
req := new(dns.Msg)
|
||||||
|
req.SetQuestion("example.com.", dns.TypeA)
|
||||||
|
|
||||||
|
_, err := o.ServeDNS(context.TODO(), rec, req)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Expected no error, got %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user