Add check for > maxUint16 sizes TYPEXXXX or CLASSXXX

These were silently wrapped in a uint16, nicer to actually give
an error.
This commit is contained in:
Miek Gieben 2013-12-05 09:54:46 +00:00
parent 857c4d663c
commit 186871d2a9
2 changed files with 15 additions and 9 deletions

View File

@ -741,15 +741,20 @@ func TestTXT(t *testing.T) {
}
func TestRR(t *testing.T) {
rr, err := NewRR("example.com IN TYPE1234 \\# 4 aabbccdd")
if err == nil {
t.Logf("%s\n", rr.String())
} else {
t.Error("Failed to parse TYPE1234 RR: ", err.Error())
_, err := NewRR("example.com IN TYPE1234 \\# 4 aabbccdd")
if err != nil {
t.Logf("Failed to parse TYPE1234 RR: ", err.Error())
t.Fail()
}
rr, err = NewRR("example.com IN TYPE1 \\# 4 0a000001")
_, err = NewRR("example.com IN TYPE655341 \\# 8 aabbccddaabbccdd")
if err == nil {
t.Error("This should not work")
t.Logf("This should not work, for TYPE655341")
t.Fail()
}
_, err = NewRR("example.com IN TYPE1 \\# 4 0a000001")
if err == nil {
t.Logf("This should not work")
t.Fail()
}
}

View File

@ -23,6 +23,7 @@ func (d debugging) Printf(format string, args ...interface{}) {
}
const maxTok = 2048 // Largest token we can return.
const maxUint16 = 1<<16 - 1
// Tokinize a RFC 1035 zone file. The tokenizer will normalize it:
// * Add ownernames if they are left blank;
@ -789,7 +790,7 @@ func zlexer(s *scan, c chan lex) {
// Extract the class number from CLASSxx
func classToInt(token string) (uint16, bool) {
class, ok := strconv.Atoi(token[5:])
if ok != nil {
if ok != nil || class > maxUint16 {
return 0, false
}
return uint16(class), true
@ -798,7 +799,7 @@ func classToInt(token string) (uint16, bool) {
// Extract the rr number from TYPExxx
func typeToInt(token string) (uint16, bool) {
typ, ok := strconv.Atoi(token[4:])
if ok != nil {
if ok != nil || typ > maxUint16 {
return 0, false
}
return uint16(typ), true