diff --git a/client_test.go b/client_test.go index 6b1d787b..edfd6b1d 100644 --- a/client_test.go +++ b/client_test.go @@ -373,12 +373,12 @@ func TestTruncatedMsg(t *testing.T) { m.Truncated = true buf, err = m.Pack() if err != nil { - t.Errorf("failed to pack truncated: %v", err) + t.Errorf("failed to pack truncated message: %v", err) } r = new(Msg) - if err = r.Unpack(buf); err != nil && err != ErrTruncated { - t.Errorf("unable to unpack truncated message: %v", err) + if err = r.Unpack(buf); err != nil { + t.Errorf("failed to unpack truncated message: %v", err) } if !r.Truncated { t.Errorf("truncated message wasn't unpacked as truncated") @@ -407,9 +407,10 @@ func TestTruncatedMsg(t *testing.T) { buf1 = buf[:len(buf)-off] r = new(Msg) - if err = r.Unpack(buf1); err != nil && err != ErrTruncated { - t.Errorf("unable to unpack cutoff message: %v", err) + if err = r.Unpack(buf1); err == nil { + t.Error("cutoff message should have failed to unpack") } + // r's header might be still usable. if !r.Truncated { t.Error("truncated cutoff message wasn't unpacked as truncated") } @@ -438,8 +439,8 @@ func TestTruncatedMsg(t *testing.T) { buf1 = buf[:len(buf)-off] r = new(Msg) - if err = r.Unpack(buf1); err != nil && err != ErrTruncated { - t.Errorf("unable to unpack cutoff message: %v", err) + if err = r.Unpack(buf1); err == nil { + t.Error("cutoff message should have failed to unpack") } if !r.Truncated { t.Error("truncated cutoff message wasn't unpacked as truncated") @@ -454,8 +455,8 @@ func TestTruncatedMsg(t *testing.T) { r = new(Msg) err = r.Unpack(buf1) - if err == nil || err == ErrTruncated { - t.Errorf("error should not be ErrTruncated from question cutoff unpack: %v", err) + if err == nil { + t.Errorf("error should be nil after question cutoff unpack: %v", err) } // Finally, if we only have the header, we don't return an error. diff --git a/msg.go b/msg.go index b1367c1f..798e15e9 100644 --- a/msg.go +++ b/msg.go @@ -46,10 +46,9 @@ var ( ErrRRset error = &Error{err: "bad rrset"} ErrSecret error = &Error{err: "no secrets defined"} ErrShortRead error = &Error{err: "short read"} - ErrSig error = &Error{err: "bad signature"} // ErrSig indicates that a signature can not be cryptographically validated. - ErrSoa error = &Error{err: "no SOA"} // ErrSOA indicates that no SOA RR was seen when doing zone transfers. - ErrTime error = &Error{err: "bad time"} // ErrTime indicates a timing error in TSIG authentication. - ErrTruncated error = &Error{err: "failed to unpack truncated message"} // ErrTruncated indicates that we failed to unpack a truncated message. We unpacked as much as we had so Msg can still be used, if desired. + ErrSig error = &Error{err: "bad signature"} // ErrSig indicates that a signature can not be cryptographically validated. + ErrSoa error = &Error{err: "no SOA"} // ErrSOA indicates that no SOA RR was seen when doing zone transfers. + ErrTime error = &Error{err: "bad time"} // ErrTime indicates a timing error in TSIG authentication. ) // Id by default, returns a 16 bits random number to be used as a @@ -813,8 +812,6 @@ func (dns *Msg) Unpack(msg []byte) (err error) { var q Question q, off, err = unpackQuestion(msg, off) if err != nil { - // Even if Truncated is set, we only will set ErrTruncated if we - // actually got the questions return err } if off1 == off { // Offset does not increase anymore, dh.Qdcount is a lie! @@ -847,10 +844,6 @@ func (dns *Msg) Unpack(msg []byte) (err error) { // TODO(miek) make this an error? // use PackOpt to let people tell how detailed the error reporting should be? // println("dns: extra bytes in dns packet", off, "<", len(msg)) - } else if dns.Truncated { - // Whether we ran into a an error or not, we want to return that it - // was truncated - err = ErrTruncated } return err }