return errTruncated after setting header bits (#442)

This commit is contained in:
Matthijs Mekking 2017-01-30 11:53:01 +01:00 committed by Miek Gieben
parent 2be0b50f7f
commit 99f84ae56e
1 changed files with 4 additions and 3 deletions

7
msg.go
View File

@ -759,9 +759,6 @@ func (dns *Msg) Unpack(msg []byte) (err error) {
if dh, off, err = unpackMsgHdr(msg, off); err != nil {
return err
}
if off == len(msg) {
return ErrTruncated
}
dns.Id = dh.Id
dns.Response = (dh.Bits & _QR) != 0
@ -775,6 +772,10 @@ func (dns *Msg) Unpack(msg []byte) (err error) {
dns.CheckingDisabled = (dh.Bits & _CD) != 0
dns.Rcode = int(dh.Bits & 0xF)
if off == len(msg) {
return ErrTruncated
}
// Optimistically use the count given to us in the header
dns.Question = make([]Question, 0, int(dh.Qdcount))