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:
parent
896cef4ce4
commit
6aa05940d5
2
msg.go
2
msg.go
|
@ -267,7 +267,7 @@ loop:
|
|||
return lenmsg, labels, ErrBuf
|
||||
}
|
||||
|
||||
if compress && bsDirty {
|
||||
if compression != nil && bsDirty {
|
||||
roBs = string(bs[:ls])
|
||||
bsDirty = false
|
||||
}
|
||||
|
|
31
msg_test.go
31
msg_test.go
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue