mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-04 03:03:14 -05:00 
			
		
		
		
	Check for empty message in typify
This commit is contained in:
		@@ -58,6 +58,10 @@ func TypeFromString(s string) (Type, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Typify classifies a message, it returns the Type.
 | 
					// Typify classifies a message, it returns the Type.
 | 
				
			||||||
func Typify(m *dns.Msg) (Type, *dns.OPT) {
 | 
					func Typify(m *dns.Msg) (Type, *dns.OPT) {
 | 
				
			||||||
 | 
						if m == nil {
 | 
				
			||||||
 | 
							return OtherError, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	opt := m.IsEdns0()
 | 
						opt := m.IsEdns0()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if len(m.Answer) > 0 && m.Rcode == dns.RcodeSuccess {
 | 
						if len(m.Answer) > 0 && m.Rcode == dns.RcodeSuccess {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,15 @@ import (
 | 
				
			|||||||
	"github.com/miekg/dns"
 | 
						"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) {
 | 
					func TestClassifyDelegation(t *testing.T) {
 | 
				
			||||||
	m := delegationMsg()
 | 
						m := delegationMsg()
 | 
				
			||||||
	mt, _ := Typify(m)
 | 
						mt, _ := Typify(m)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user