Don't crash on emtpy string in compressionLenSearch

Fixes #105
This commit is contained in:
Miek Gieben 2014-08-22 08:46:24 +00:00
parent 9f5fcf8459
commit 34f5a12bfc
2 changed files with 5 additions and 2 deletions

View File

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

3
msg.go
View File

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