From 88ab058ba296a253cc43ace070e717a54ac01b9a Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Wed, 2 Sep 2026 07:58:49 -0700 Subject: [PATCH] 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 * Fix lint Signed-off-by: Yong Tang --------- Signed-off-by: Yong Tang --- plugin/minimal/minimal.go | 3 +++ plugin/minimal/minimal_test.go | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/plugin/minimal/minimal.go b/plugin/minimal/minimal.go index 0bac6a373..b067395b2 100644 --- a/plugin/minimal/minimal.go +++ b/plugin/minimal/minimal.go @@ -26,6 +26,9 @@ func (m *minimalHandler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r * if err != nil { return rcode, err } + if nw.Msg == nil { + return rcode, nil + } ty, _ := response.Typify(nw.Msg, time.Now().UTC()) cl := response.Classify(ty) diff --git a/plugin/minimal/minimal_test.go b/plugin/minimal/minimal_test.go index c784226ab..337ad3184 100644 --- a/plugin/minimal/minimal_test.go +++ b/plugin/minimal/minimal_test.go @@ -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) + } +}