Fix DS overflow when unpacking

This commit is contained in:
Miek Gieben 2012-01-23 20:29:47 +01:00
parent 7b67cbff49
commit 04cbdae47a

8
msg.go
View File

@ -764,10 +764,6 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
case "hex": case "hex":
// Rest of the RR is hex encoded, network order an issue here? // Rest of the RR is hex encoded, network order an issue here?
rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint()) rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint())
if off+rdlength > lenmsg {
// too large
return lenmsg, false
}
var consumed int var consumed int
switch val.Type().Name() { switch val.Type().Name() {
case "RR_DS": case "RR_DS":
@ -781,6 +777,10 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
default: default:
consumed = 0 // return len(msg), false? consumed = 0 // return len(msg), false?
} }
if off+rdlength-consumed > lenmsg {
println("dns: overflow when unpacking hex string")
return lenmsg, false
}
s = hex.EncodeToString(msg[off : off+rdlength-consumed]) s = hex.EncodeToString(msg[off : off+rdlength-consumed])
off += rdlength - consumed off += rdlength - consumed
case "base64": case "base64":