If the TC bit is set return a valid but smaller message

If the TC bit is set in a message, we will probably try to parse
half a message, which will fail. To fix this just return a message
header and the question section and don't parse the rest.
This commit is contained in:
Miek Gieben 2014-02-05 21:47:26 +00:00
parent 95fd782f44
commit 4f6fef6777
1 changed files with 10 additions and 1 deletions

11
msg.go
View File

@ -1205,7 +1205,7 @@ func packBase32(s []byte) ([]byte, error) {
return buf, nil
}
// PackRR packs a resource record rr into msg[off:].
// PackRR packs a resource record rr into msg[off:].
// See PackDomainName for documentation about the compression.
func PackRR(rr RR, msg []byte, off int, compression map[string]int, compress bool) (off1 int, err error) {
if rr == nil {
@ -1436,6 +1436,15 @@ func (dns *Msg) Unpack(msg []byte) (err error) {
return err
}
}
// If we have seen a TC bit being set, we return here, without
// an error, because technically it isn't an error. So we return
// without parsing, the potentially corrupt packet.
if dns.Truncated {
dns.Answer = nil
dns.Ns = nil
dns.Extra = nil
return nil
}
for i := 0; i < len(dns.Answer); i++ {
dns.Answer[i], off, err = UnpackRR(msg, off)
if err != nil {