From 56c04f1fecfd61472b75873d017d97e65cc78325 Mon Sep 17 00:00:00 2001 From: Tom Thorogood Date: Tue, 30 Apr 2019 17:44:07 +0930 Subject: [PATCH] Fix dns:"hex" field len being off-by-one (#959) dns:"hex" fields are not packed with any extra trailing byte. This was causing a mismatch between PackRR and Len. --- types_generate.go | 4 +--- ztypes.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/types_generate.go b/types_generate.go index cbb4a00c..8cda2a74 100644 --- a/types_generate.go +++ b/types_generate.go @@ -189,10 +189,8 @@ func main() { o("l += base64.StdEncoding.DecodedLen(len(rr.%s))\n") case strings.HasPrefix(st.Tag(i), `dns:"size-hex:`): // this has an extra field where the length is stored o("l += len(rr.%s)/2\n") - case strings.HasPrefix(st.Tag(i), `dns:"size-hex`): - fallthrough case st.Tag(i) == `dns:"hex"`: - o("l += len(rr.%s)/2 + 1\n") + o("l += len(rr.%s)/2\n") case st.Tag(i) == `dns:"any"`: o("l += len(rr.%s)\n") case st.Tag(i) == `dns:"a"`: diff --git a/ztypes.go b/ztypes.go index 495a83e3..f7ec8352 100644 --- a/ztypes.go +++ b/ztypes.go @@ -312,12 +312,12 @@ func (rr *DS) len(off int, compression map[string]struct{}) int { l += 2 // KeyTag l++ // Algorithm l++ // DigestType - l += len(rr.Digest)/2 + 1 + l += len(rr.Digest) / 2 return l } func (rr *EID) len(off int, compression map[string]struct{}) int { l := rr.Hdr.len(off, compression) - l += len(rr.Endpoint)/2 + 1 + l += len(rr.Endpoint) / 2 return l } func (rr *EUI48) len(off int, compression map[string]struct{}) int { @@ -452,7 +452,7 @@ func (rr *NID) len(off int, compression map[string]struct{}) int { } func (rr *NIMLOC) len(off int, compression map[string]struct{}) int { l := rr.Hdr.len(off, compression) - l += len(rr.Locator)/2 + 1 + l += len(rr.Locator) / 2 return l } func (rr *NINFO) len(off int, compression map[string]struct{}) int { @@ -505,7 +505,7 @@ func (rr *PX) len(off int, compression map[string]struct{}) int { } func (rr *RFC3597) len(off int, compression map[string]struct{}) int { l := rr.Hdr.len(off, compression) - l += len(rr.Rdata)/2 + 1 + l += len(rr.Rdata) / 2 return l } func (rr *RKEY) len(off int, compression map[string]struct{}) int { @@ -546,7 +546,7 @@ func (rr *SMIMEA) len(off int, compression map[string]struct{}) int { l++ // Usage l++ // Selector l++ // MatchingType - l += len(rr.Certificate)/2 + 1 + l += len(rr.Certificate) / 2 return l } func (rr *SOA) len(off int, compression map[string]struct{}) int { @@ -579,7 +579,7 @@ func (rr *SSHFP) len(off int, compression map[string]struct{}) int { l := rr.Hdr.len(off, compression) l++ // Algorithm l++ // Type - l += len(rr.FingerPrint)/2 + 1 + l += len(rr.FingerPrint) / 2 return l } func (rr *TA) len(off int, compression map[string]struct{}) int { @@ -587,7 +587,7 @@ func (rr *TA) len(off int, compression map[string]struct{}) int { l += 2 // KeyTag l++ // Algorithm l++ // DigestType - l += len(rr.Digest)/2 + 1 + l += len(rr.Digest) / 2 return l } func (rr *TALINK) len(off int, compression map[string]struct{}) int { @@ -614,7 +614,7 @@ func (rr *TLSA) len(off int, compression map[string]struct{}) int { l++ // Usage l++ // Selector l++ // MatchingType - l += len(rr.Certificate)/2 + 1 + l += len(rr.Certificate) / 2 return l } func (rr *TSIG) len(off int, compression map[string]struct{}) int {