diff --git a/middleware/pkg/response/typify.go b/middleware/pkg/response/typify.go index 20ec13453..f121ecccf 100644 --- a/middleware/pkg/response/typify.go +++ b/middleware/pkg/response/typify.go @@ -58,6 +58,10 @@ func TypeFromString(s string) (Type, error) { // Typify classifies a message, it returns the Type. func Typify(m *dns.Msg) (Type, *dns.OPT) { + if m == nil { + return OtherError, nil + } + opt := m.IsEdns0() if len(m.Answer) > 0 && m.Rcode == dns.RcodeSuccess { diff --git a/middleware/pkg/response/typify_test.go b/middleware/pkg/response/typify_test.go index dbd11c129..8d0644e3b 100644 --- a/middleware/pkg/response/typify_test.go +++ b/middleware/pkg/response/typify_test.go @@ -8,6 +8,15 @@ import ( "github.com/miekg/dns" ) +func TestTypifyNilMsg(t *testing.T) { + var m *dns.Msg = nil + + ty, _ := Typify(m) + if ty != OtherError { + t.Errorf("message wrongly typified, expected OtherError, got %d", ty) + } +} + func TestClassifyDelegation(t *testing.T) { m := delegationMsg() mt, _ := Typify(m)