Return an error when packStruct fails

When doing the recursion be sure to catch the error that
might be generated.

Reported-by: madotsuki
This commit is contained in:
Miek Gieben 2013-03-18 17:56:48 +00:00
parent c88ac95260
commit ba6c414fe4
1 changed files with 9 additions and 0 deletions

9
msg.go
View File

@ -530,6 +530,9 @@ func packStructValue(val reflect.Value, msg []byte, off int, compression map[str
}
case reflect.Struct:
off, err = packStructValue(fv, msg, off, compression, compress)
if err != nil {
return lenmsg, err
}
case reflect.Uint8:
if off+1 > lenmsg {
return lenmsg, &Error{Err: "overflow packing uint8"}
@ -865,6 +868,9 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, err er
}
case reflect.Struct:
off, err = unpackStructValue(fv, msg, off)
if err != nil {
return lenmsg, err
}
if val.Type().Field(i).Name == "Hdr" {
rdstart = off
}
@ -1227,6 +1233,9 @@ func (dns *Msg) Pack() (msg []byte, err error) {
// Pack it in: header and then the pieces.
off := 0
off, err = packStructCompress(&dh, msg, off, compression, dns.Compress)
if err != nil {
return nil, err
}
for i := 0; i < len(question); i++ {
off, err = packStructCompress(&question[i], msg, off, compression, dns.Compress)
if err != nil {