Reset roBs even if compress is false in packDomainName

By only resetting roBs when compress is true, the compression map can
end up with inconsistent entries between compress being true and false.
This commit is contained in:
Tom Thorogood 2018-11-26 16:04:34 +10:30
parent 896cef4ce4
commit 6aa05940d5
No known key found for this signature in database
GPG Key ID: 86C63CDA416C6D2F
2 changed files with 18 additions and 15 deletions

2
msg.go
View File

@ -267,7 +267,7 @@ loop:
return lenmsg, labels, ErrBuf
}
if compress && bsDirty {
if compression != nil && bsDirty {
roBs = string(bs[:ls])
bsDirty = false
}

View File

@ -215,22 +215,25 @@ 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 _, compress := range []bool{true, false} {
compression := make(map[string]int)
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)
_, err := PackDomainName(`www\.this.is.\131an.example.org.`, msg, 0, compression, compress)
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)
}
}
}
}