Dont allow the question section to be compressed

This commit is contained in:
Miek Gieben 2012-01-11 16:16:09 +01:00
parent f39d939f52
commit 6d95911558
5 changed files with 10 additions and 9 deletions

View File

@ -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
}

9
msg.go
View File

@ -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")

View File

@ -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 ""
}

View File

@ -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

View File

@ -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
}