Check for empty message in typify

This commit is contained in:
Miek Gieben 2016-10-17 10:26:24 +00:00
parent be3c0195b6
commit 03bc071774
2 changed files with 13 additions and 0 deletions

View file

@ -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 {

View file

@ -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)