mirror of
https://github.com/miekg/dns.git
synced 2025-10-10 17:31:01 +02:00
Always use "." for the root domain.
This commit is contained in:
parent
c14f87ef81
commit
5fc37375db
58
msg.go
58
msg.go
@ -313,6 +313,9 @@ Loop:
|
|||||||
case 0x00:
|
case 0x00:
|
||||||
if c == 0x00 {
|
if c == 0x00 {
|
||||||
// end of name
|
// end of name
|
||||||
|
if s == "" {
|
||||||
|
return ".", off, true
|
||||||
|
}
|
||||||
break Loop
|
break Loop
|
||||||
}
|
}
|
||||||
// literal string
|
// literal string
|
||||||
@ -641,6 +644,7 @@ func packStructCompress(any interface{}, msg []byte, off int, compression map[st
|
|||||||
// Unpack a reflect.StructValue from msg.
|
// Unpack a reflect.StructValue from msg.
|
||||||
// Same restrictions as packStructValue.
|
// Same restrictions as packStructValue.
|
||||||
func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool) {
|
func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool) {
|
||||||
|
var rdstart int
|
||||||
for i := 0; i < val.NumField(); i++ {
|
for i := 0; i < val.NumField(); i++ {
|
||||||
// f := val.Type().Field(i)
|
// f := val.Type().Field(i)
|
||||||
lenmsg := len(msg)
|
lenmsg := len(msg)
|
||||||
@ -718,15 +722,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
|
|||||||
case "nsec": // NSEC/NSEC3
|
case "nsec": // NSEC/NSEC3
|
||||||
// Rest of the Record is the type bitmap
|
// Rest of the Record is the type bitmap
|
||||||
rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint())
|
rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint())
|
||||||
var endrr int
|
endrr := rdstart + rdlength
|
||||||
// for NSEC and NSEC3 calculate back what end of the RR must be
|
|
||||||
switch val.Type().Name() {
|
|
||||||
case "RR_NSEC":
|
|
||||||
endrr = off + (rdlength - (len(val.FieldByName("NextDomain").String()) + 1))
|
|
||||||
case "RR_NSEC3":
|
|
||||||
// NextDomain is always 20 for NextDomain
|
|
||||||
endrr = off + (rdlength - (20 + 6 + len(val.FieldByName("Salt").String())/2))
|
|
||||||
}
|
|
||||||
|
|
||||||
if off+2 > lenmsg {
|
if off+2 > lenmsg {
|
||||||
println("dns: overflow unpacking NSEC")
|
println("dns: overflow unpacking NSEC")
|
||||||
@ -787,6 +783,9 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
|
|||||||
}
|
}
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
off, ok = unpackStructValue(fv, msg, off)
|
off, ok = unpackStructValue(fv, msg, off)
|
||||||
|
if val.Type().Field(i).Name == "Hdr" {
|
||||||
|
rdstart = off
|
||||||
|
}
|
||||||
case reflect.Uint8:
|
case reflect.Uint8:
|
||||||
if off+1 > lenmsg {
|
if off+1 > lenmsg {
|
||||||
println("dns: overflow unpacking uint8")
|
println("dns: overflow unpacking uint8")
|
||||||
@ -828,48 +827,23 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
|
|||||||
case "hex":
|
case "hex":
|
||||||
// Rest of the RR is hex encoded, network order an issue here?
|
// Rest of the RR is hex encoded, network order an issue here?
|
||||||
rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint())
|
rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint())
|
||||||
var consumed int
|
endrr := rdstart + rdlength
|
||||||
switch val.Type().Name() {
|
if endrr > lenmsg {
|
||||||
case "RR_DS":
|
|
||||||
consumed = 4 // KeyTag(2) + Algorithm(1) + DigestType(1)
|
|
||||||
case "RR_SSHFP":
|
|
||||||
consumed = 2 // Algorithm(1) + Type(1)
|
|
||||||
case "RR_NSEC3PARAM":
|
|
||||||
consumed = 5 // Hash(1) + Flags(1) + Iterations(2) + SaltLength(1)
|
|
||||||
case "RR_RFC3597":
|
|
||||||
fallthrough // Rest is the unknown data
|
|
||||||
default:
|
|
||||||
consumed = 0 // return len(msg), false?
|
|
||||||
}
|
|
||||||
if off+rdlength-consumed > lenmsg {
|
|
||||||
println("dns: overflow when unpacking hex string")
|
println("dns: overflow when unpacking hex string")
|
||||||
return lenmsg, false
|
return lenmsg, false
|
||||||
}
|
}
|
||||||
s = hex.EncodeToString(msg[off : off+rdlength-consumed])
|
s = hex.EncodeToString(msg[off : endrr])
|
||||||
off += rdlength - consumed
|
off = endrr
|
||||||
case "base64":
|
case "base64":
|
||||||
// Rest of the RR is base64 encoded value
|
// Rest of the RR is base64 encoded value
|
||||||
rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint())
|
rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint())
|
||||||
// Need to know how much of rdlength is already consumed, in this packet
|
endrr := rdstart + rdlength
|
||||||
var consumed int
|
if endrr > lenmsg {
|
||||||
switch val.Type().Name() {
|
|
||||||
case "RR_DNSKEY":
|
|
||||||
consumed = 4 // Flags(2) + Protocol(1) + Algorithm(1)
|
|
||||||
case "RR_RRSIG":
|
|
||||||
consumed = 18 // TypeCovered(2) + Algorithm(1) + Labels(1) +
|
|
||||||
// OrigTTL(4) + SigExpir(4) + SigIncep(4) + KeyTag(2) + len(signername)
|
|
||||||
// Should already be set in the sequence of parsing (comes before)
|
|
||||||
// Work because of rfc4034, section 3.17
|
|
||||||
consumed += len(val.FieldByName("SignerName").String()) + 1
|
|
||||||
default:
|
|
||||||
consumed = 0 // TODO, maybe error?
|
|
||||||
}
|
|
||||||
if off+rdlength-consumed > lenmsg {
|
|
||||||
println("dns: failure unpacking base64")
|
println("dns: failure unpacking base64")
|
||||||
return lenmsg, false
|
return lenmsg, false
|
||||||
}
|
}
|
||||||
s = unpackBase64(msg[off : off+rdlength-consumed])
|
s = unpackBase64(msg[off : endrr])
|
||||||
off += rdlength - consumed
|
off = endrr
|
||||||
case "cdomain-name":
|
case "cdomain-name":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "domain-name":
|
case "domain-name":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user