Fix rawSetRdlength

When searching for the start of the rdata, the offset wasn't properly
calculated. This only impacted names with \DDD in it (weirdly enough).
This commit is contained in:
Miek Gieben 2013-06-14 11:35:06 +00:00
parent 3f348f173b
commit 9ee7c27e18
3 changed files with 14 additions and 11 deletions

2
msg.go
View File

@ -245,13 +245,11 @@ func PackDomainName(s string, msg []byte, off int, compression map[string]int, c
if i+2 < ls && bs[i] >= '0' && bs[i] <= '9' &&
bs[i+1] >= '0' && bs[i+1] <= '9' &&
bs[i+2] >= '0' && bs[i+2] <= '9' {
bs[i] = byte((bs[i]-'0')*100 + (bs[i+1]-'0')*10 + (bs[i+2] - '0'))
for j := i + 1; j < ls-2; j++ {
bs[j] = bs[j+2]
}
ls -= 2
//fmt.Printf("%10s %v\n", s, msg[:])
}
continue
}

View File

@ -810,14 +810,13 @@ func TestPtrPack(t *testing.T) {
func TestDigit(t *testing.T) {
tests := map[string]byte{
"miek\\000.nl. 100 IN A 127.0.0.1": 0,
"miek\\001.nl. 100 IN A 127.0.0.1": 1,
"miek\\004.nl. 100 IN A 127.0.0.1": 4,
"miek\\254.nl. 100 IN A 127.0.0.1": 254,
"miek\\255.nl. 100 IN A 127.0.0.1": 255,
"miek\\256.nl. 100 IN A 127.0.0.1": 0,
"miek\\257.nl. 100 IN A 127.0.0.1": 1,
"miek4.nl. 100 IN A 127.0.0.1": 52,
"miek\\000.nl. 100 IN TXT \"A\"": 0,
"miek\\001.nl. 100 IN TXT \"A\"": 1,
"miek\\254.nl. 100 IN TXT \"A\"": 254,
"miek\\255.nl. 100 IN TXT \"A\"": 255,
"miek\\256.nl. 100 IN TXT \"A\"": 0,
"miek\\257.nl. 100 IN TXT \"A\"": 1,
"miek\\004.nl. 100 IN TXT \"A\"": 4,
}
for s, i := range tests {
r, e := NewRR(s)
@ -831,6 +830,8 @@ func TestDigit(t *testing.T) {
t.Fatalf("5 pos must be %d, is %d", i, buf[5])
}
r1, _, _ := UnpackRR(buf, 0)
t.Logf("%s\n\n", r1)
if r1.Header().Ttl != 100 {
t.Fatalf("Ttl should %d, is %d", 100, r1.Header().Ttl)
}
}
}

View File

@ -71,6 +71,10 @@ Loop:
// End of the domainname
break Loop
}
if off+c>l {
return false
}
off +=c
case 0xC0:
// pointer, next byte included, ends domainname