diff --git a/dns_test.go b/dns_test.go index f91b4597..3ad8a894 100644 --- a/dns_test.go +++ b/dns_test.go @@ -316,7 +316,7 @@ func TestMsgLength2(t *testing.T) { } } -func testMsgLengthCompressionMalformed(t *testing.T) { +func TestMsgLengthCompressionMalformed(t *testing.T) { // SOA with empty hostmaster, which is illegal soa := &SOA{Hdr: RR_Header{Name: ".", Rrtype: TypeSOA, Class: ClassINET, Ttl: 12345}, Ns: ".", @@ -329,7 +329,7 @@ func testMsgLengthCompressionMalformed(t *testing.T) { m := new(Msg) m.Compress = true m.Ns = []RR{soa} - m.Len() + m.Len() // Should not crash. } func BenchmarkMsgLength(b *testing.B) { diff --git a/msg.go b/msg.go index 6a7755c6..cab1842d 100644 --- a/msg.go +++ b/msg.go @@ -1702,6 +1702,9 @@ func compressionLenHelper(c map[string]int, s string) { func compressionLenSearch(c map[string]int, s string) (int, bool) { off := 0 end := false + if s == "" { // don't bork on bogus data + return 0, false + } for { if _, ok := c[s[off:]]; ok { return len(s[off:]), true