\DDD to buf parsing fails (sometimes)

Added test (that fails for now)
This commit is contained in:
Miek Gieben 2013-06-14 07:31:22 +01:00
parent 6ee0baab56
commit 3f348f173b
2 changed files with 30 additions and 1 deletions

4
msg.go
View File

@ -218,6 +218,7 @@ func PackDomainName(s string, msg []byte, off int, compression map[string]int, c
if ls == 0 || s[ls-1] != '.' {
return lenmsg, ErrFqdn
}
// TODO(miek) do I really need to string conversions in here???
// Each dot ends a segment of the name.
// We trade each dot byte for a length byte.
@ -237,10 +238,10 @@ func PackDomainName(s string, msg []byte, off int, compression map[string]int, c
bs[j] = bs[j+1]
}
ls--
// check for \DDD
if off+1 > lenmsg {
return lenmsg, ErrBuf
}
// check for \DDD
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' {
@ -250,6 +251,7 @@ func PackDomainName(s string, msg []byte, off int, compression map[string]int, c
bs[j] = bs[j+2]
}
ls -= 2
//fmt.Printf("%10s %v\n", s, msg[:])
}
continue
}

View File

@ -807,3 +807,30 @@ func TestPtrPack(t *testing.T) {
t.Error("Failed to parse ", err.Error())
}
}
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,
}
for s, i := range tests {
r, e := NewRR(s)
buf := make([]byte, 40)
if e != nil {
t.Fatalf("Failed to parse %s\n", e.Error())
}
PackRR(r, buf, 0, nil, false)
t.Logf("%v\n", buf)
if buf[5] != i {
t.Fatalf("5 pos must be %d, is %d", i, buf[5])
}
r1, _, _ := UnpackRR(buf, 0)
t.Logf("%s\n\n", r1)
}
}