Fix TXT validation

This commit is contained in:
Miek Gieben 2012-02-22 22:11:40 +01:00
parent 1571b7a97b
commit c7dd37b000
1 changed files with 17 additions and 17 deletions

34
msg.go
View File

@ -373,12 +373,12 @@ func packStructValue(val reflect.Value, msg []byte, off int, compression map[str
case "domain-name": case "domain-name":
for j := 0; j < val.Field(i).Len(); j++ { for j := 0; j < val.Field(i).Len(); j++ {
element := val.Field(i).Index(j).String() element := val.Field(i).Index(j).String()
off, ok = PackDomainName(element, msg, off, compression, false && compress) off, ok = PackDomainName(element, msg, off, compression, false && compress)
if ! ok { if !ok {
println("dns: overflow packing domain-name", off) println("dns: overflow packing domain-name", off)
return lenmsg, false return lenmsg, false
} }
} }
case "txt": case "txt":
for j := 0; j < val.Field(i).Len(); j++ { for j := 0; j < val.Field(i).Len(); j++ {
element := val.Field(i).Index(j).String() element := val.Field(i).Index(j).String()
@ -653,20 +653,20 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
return lenmsg, false return lenmsg, false
case "domain-name": case "domain-name":
// HIP record slice of name (or none) // HIP record slice of name (or none)
servers := make([]string, 0) servers := make([]string, 0)
var s string var s string
for off < lenmsg { for off < lenmsg {
s, off, ok = UnpackDomainName(msg, off) s, off, ok = UnpackDomainName(msg, off)
if !ok { if !ok {
println("dns: failure unpacking domain-name") println("dns: failure unpacking domain-name")
return lenmsg, false return lenmsg, false
} }
servers = append(servers, s) servers = append(servers, s)
} }
fv.Set(reflect.ValueOf(servers)) fv.Set(reflect.ValueOf(servers))
case "txt": case "txt":
txt := make([]string, 0) txt := make([]string, 0)
rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint()) rdlength := off + int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint())
Txts: Txts:
l := int(msg[off]) l := int(msg[off])
if off+l+1 > lenmsg { if off+l+1 > lenmsg {