Fix garbage after name in compression map

When packDomainName is called with an escaped domain name and compress
being true, bs wasn't be truncated to the correct length and would
include garbage that would be included in the compression map.
This commit is contained in:
Tom Thorogood 2018-11-26 15:53:29 +10:30
parent 260b5b401d
commit 5547fd63a0
No known key found for this signature in database
GPG Key ID: 86C63CDA416C6D2F
2 changed files with 23 additions and 1 deletions

2
msg.go
View File

@ -265,7 +265,7 @@ loop:
}
if compress && !bsFresh {
roBs = string(bs)
roBs = string(bs[:ls])
bsFresh = true
}

View File

@ -213,6 +213,28 @@ func TestUnpackDomainName(t *testing.T) {
}
}
func TestPackDomainNameCompressionMap(t *testing.T) {
msg := make([]byte, 256)
compression := make(map[string]int)
_, err := PackDomainName(`www\.this.is.\131an.example.org.`, msg, 0, compression, true)
if err != nil {
t.Fatalf("PackDomainName failed: %v", err)
}
for _, dname := range []string{
`www.this.is.\131an.example.org.`,
`is.\131an.example.org.`,
"\x83an.example.org.",
`example.org.`,
`org.`,
} {
if _, ok := compression[dname]; !ok {
t.Errorf("expected to find %q in compression map", dname)
}
}
}
func TestPackDomainNameNSECTypeBitmap(t *testing.T) {
ownername := "some-very-long-ownername.com."
msg := &Msg{