Dont allow the question section to be compressed
This commit is contained in:
parent
f39d939f52
commit
6d95911558
|
@ -133,7 +133,7 @@ func (k *RR_DNSKEY) ToDS(h int) *RR_DS {
|
||||||
wire = wire[:n]
|
wire = wire[:n]
|
||||||
|
|
||||||
owner := make([]byte, 255)
|
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 {
|
if !ok1 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
9
msg.go
9
msg.go
|
@ -176,7 +176,7 @@ var Rcode_str = map[int]string{
|
||||||
// PackDomainName packs a domain name s into msg[off:].
|
// PackDomainName packs a domain name s into msg[off:].
|
||||||
// Domain names are a sequence of counted strings
|
// Domain names are a sequence of counted strings
|
||||||
// split at the dots. They end with a zero-length string.
|
// 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.
|
// Add trailing dot to canonicalize name.
|
||||||
lenmsg := len(msg)
|
lenmsg := len(msg)
|
||||||
if n := len(s); n == 0 || s[n-1] != '.' {
|
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
|
// keep the pointer offset we get back and store
|
||||||
// the offset of the current name, because that's
|
// the offset of the current name, because that's
|
||||||
// where we need to insert the pointer later
|
// 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
|
pointer = p // Where to point to
|
||||||
nameoffset = offset // Where to point from
|
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
|
fallthrough // No compression
|
||||||
case "cdomain-name":
|
case "cdomain-name":
|
||||||
if val.Type().Field(i).Tag == "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 {
|
} else {
|
||||||
off, ok = PackDomainName(s, msg, off, nil)
|
off, ok = PackDomainName(s, msg, off, compression, false)
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
//fmt.Fprintf(os.Stderr, "dns: overflow packing domain-name")
|
//fmt.Fprintf(os.Stderr, "dns: overflow packing domain-name")
|
||||||
|
|
2
nsec3.go
2
nsec3.go
|
@ -23,7 +23,7 @@ func HashName(label string, ha, iter int, salt string) string {
|
||||||
}
|
}
|
||||||
wire = wire[:n]
|
wire = wire[:n]
|
||||||
name := make([]byte, 255)
|
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 {
|
if !ok1 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ Activate: 20110302104537`
|
||||||
|
|
||||||
func TestDotInName(t *testing.T) {
|
func TestDotInName(t *testing.T) {
|
||||||
buf := make([]byte, 20)
|
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
|
// index 3 must be a real dot
|
||||||
if buf[3] != '.' {
|
if buf[3] != '.' {
|
||||||
t.Log("Dot should be a real dot")
|
t.Log("Dot should be a real dot")
|
||||||
|
@ -136,7 +136,7 @@ func TestDomainName(t *testing.T) {
|
||||||
|
|
||||||
|
|
||||||
for _, ts := range tests {
|
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.Log("Not a valid domain name")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
continue
|
continue
|
||||||
|
|
2
types.go
2
types.go
|
@ -129,7 +129,7 @@ const (
|
||||||
|
|
||||||
// DNS queries.
|
// DNS queries.
|
||||||
type Question struct {
|
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
|
Qtype uint16
|
||||||
Qclass uint16
|
Qclass uint16
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue