From 6d959115584f4861ef9c1287f21510d9e41b0c4f Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Wed, 11 Jan 2012 16:16:09 +0100 Subject: [PATCH] Dont allow the question section to be compressed --- dnssec.go | 2 +- msg.go | 9 +++++---- nsec3.go | 2 +- parse_test.go | 4 ++-- types.go | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/dnssec.go b/dnssec.go index 413b7e84..1afd0bbc 100644 --- a/dnssec.go +++ b/dnssec.go @@ -133,7 +133,7 @@ func (k *RR_DNSKEY) ToDS(h int) *RR_DS { wire = wire[:n] owner := make([]byte, 255) - off, ok1 := PackDomainName(k.Hdr.Name, owner, 0, nil) + off, ok1 := PackDomainName(k.Hdr.Name, owner, 0, nil, false) if !ok1 { return nil } diff --git a/msg.go b/msg.go index 39683cb6..3ec5640b 100644 --- a/msg.go +++ b/msg.go @@ -176,7 +176,7 @@ var Rcode_str = map[int]string{ // PackDomainName packs a domain name s into msg[off:]. // Domain names are a sequence of counted strings // split at the dots. They end with a zero-length string. -func PackDomainName(s string, msg []byte, off int, compression map[string]int) (off1 int, ok bool) { +func PackDomainName(s string, msg []byte, off int, compression map[string]int, compress bool) (off1 int, ok bool) { // Add trailing dot to canonicalize name. lenmsg := len(msg) if n := len(s); n == 0 || s[n-1] != '.' { @@ -234,7 +234,8 @@ func PackDomainName(s string, msg []byte, off int, compression map[string]int) ( // keep the pointer offset we get back and store // the offset of the current name, because that's // where we need to insert the pointer later - if pointer == -1 { + // If compress is true, we allowed to compress this dname + if pointer == -1 && compress { pointer = p // Where to point to nameoffset = offset // Where to point from } @@ -484,9 +485,9 @@ func packStructValue(val reflect.Value, msg []byte, off int, compression map[str fallthrough // No compression case "cdomain-name": if val.Type().Field(i).Tag == "cdomain-name" { - off, ok = PackDomainName(s, msg, off, compression) + off, ok = PackDomainName(s, msg, off, compression, true) } else { - off, ok = PackDomainName(s, msg, off, nil) + off, ok = PackDomainName(s, msg, off, compression, false) } if !ok { //fmt.Fprintf(os.Stderr, "dns: overflow packing domain-name") diff --git a/nsec3.go b/nsec3.go index 684ac337..2124f60b 100644 --- a/nsec3.go +++ b/nsec3.go @@ -23,7 +23,7 @@ func HashName(label string, ha, iter int, salt string) string { } wire = wire[:n] name := make([]byte, 255) - off, ok1 := PackDomainName(strings.ToLower(label), name, 0, nil) + off, ok1 := PackDomainName(strings.ToLower(label), name, 0, nil, false) if !ok1 { return "" } diff --git a/parse_test.go b/parse_test.go index 0a5c0615..976f4727 100644 --- a/parse_test.go +++ b/parse_test.go @@ -76,7 +76,7 @@ Activate: 20110302104537` func TestDotInName(t *testing.T) { buf := make([]byte, 20) - PackDomainName("aa\\.bb.nl.", buf, 0, nil) + PackDomainName("aa\\.bb.nl.", buf, 0, nil, false) // index 3 must be a real dot if buf[3] != '.' { t.Log("Dot should be a real dot") @@ -136,7 +136,7 @@ func TestDomainName(t *testing.T) { for _, ts := range tests { - if _, ok := PackDomainName(ts, dbuff, 0, nil); !ok { + if _, ok := PackDomainName(ts, dbuff, 0, nil, false); !ok { t.Log("Not a valid domain name") t.Fail() continue diff --git a/types.go b/types.go index 471e25b1..6c81de8d 100644 --- a/types.go +++ b/types.go @@ -129,7 +129,7 @@ const ( // DNS queries. type Question struct { - Name string "cdomain-name" // "cdomain-name" specifies encoding (and may be compressed) + Name string "domain-name" // "cdomain-name" specifies encoding (and may be compressed) Qtype uint16 Qclass uint16 }