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:
parent
260b5b401d
commit
5547fd63a0
2
msg.go
2
msg.go
|
@ -265,7 +265,7 @@ loop:
|
|||
}
|
||||
|
||||
if compress && !bsFresh {
|
||||
roBs = string(bs)
|
||||
roBs = string(bs[:ls])
|
||||
bsFresh = true
|
||||
}
|
||||
|
||||
|
|
22
msg_test.go
22
msg_test.go
|
@ -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{
|
||||
|
|
Loading…
Reference in New Issue