This commit is contained in:
Miek Gieben 2011-12-09 16:07:17 +01:00
parent 794ad60217
commit 88c12387f9
1 changed files with 46 additions and 52 deletions

98
msg.go
View File

@ -537,67 +537,61 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
fv.Set(reflect.ValueOf(opt)) fv.Set(reflect.ValueOf(opt))
off = off1 + int(optlen) off = off1 + int(optlen)
case "NSEC": // NSEC/NSEC3 case "NSEC": // NSEC/NSEC3
// Rest of the Record it the type bitmap
rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint())
rdlength -= (1 + 1 + 2 + len(val.FieldByName("NextDomain").String()) + 1)
if off+1 > lenmsg { if off+1 > lenmsg {
//fmt.Fprintf(os.Stderr, "dns: overflow unpacking NSEC") //fmt.Fprintf(os.Stderr, "dns: overflow unpacking NSEC")
return lenmsg, false return lenmsg, false
} }
// Fix multple windows TODO(mg)
nsec := make([]uint16, 256) // use append TODO(mg)
ni := 0
window := int(msg[off])
blocks := int(msg[off+1])
if off+blocks > lenmsg {
//fmt.Fprintf(os.Stderr, "dns: overflow unpacking NSEC")
return lenmsg, false
}
if blocks == 0 {
// Nothing encoded in this window
// Kinda lame to alloc above and to clear it here
nsec = nsec[:ni]
fv.Set(reflect.ValueOf(nsec))
break
}
off += 2 nsec := make([]uint16, 0)
for j := 0; j < blocks; j++ { length := 0
b := msg[off+j] window := 0
// Check the bits one by one, and set the type seen := 2
if b&0x80 == 0x80 { for seen < rdlength {
nsec[ni] = uint16(window*256 + j*8 + 0) window = int(msg[off])
ni++ length = int(msg[off+1])
if length == 0 || length > 32 {
//fmt.Fprintf(os.Stderr, "dns: overflow unpacking NSEC")
println("illegal length value", length)
break
// return lenmsg, false
} }
if b&0x40 == 0x40 {
nsec[ni] = uint16(window*256 + j*8 + 1) off += 2
ni++ for j := 0; j < length; j++ {
} b := msg[off+j]
if b&0x20 == 0x20 { // Check the bits one by one, and set the type
nsec[ni] = uint16(window*256 + j*8 + 2) if b&0x80 == 0x80 {
ni++ nsec = append(nsec, uint16(window*256+j*8+0))
} }
if b&0x10 == 0x10 { if b&0x40 == 0x40 {
nsec[ni] = uint16(window*256 + j*8 + 3) nsec = append(nsec, uint16(window*256+j*8+1))
ni++ }
} if b&0x20 == 0x20 {
if b&0x8 == 0x8 { nsec = append(nsec, uint16(window*256+j*8+2))
nsec[ni] = uint16(window*256 + j*8 + 4) }
ni++ if b&0x10 == 0x10 {
} nsec = append(nsec, uint16(window*256+j*8+3))
if b&0x4 == 0x4 { }
nsec[ni] = uint16(window*256 + j*8 + 5) if b&0x8 == 0x8 {
ni++ nsec = append(nsec, uint16(window*256+j*8+4))
} }
if b&0x2 == 0x2 { if b&0x4 == 0x4 {
nsec[ni] = uint16(window*256 + j*8 + 6) nsec = append(nsec, uint16(window*256+j*8+5))
ni++ }
} if b&0x2 == 0x2 {
if b&0x1 == 0x1 { nsec = append(nsec, uint16(window*256+j*8+6))
nsec[ni] = uint16(window*256 + j*8 + 7) }
ni++ if b&0x1 == 0x1 {
nsec = append(nsec, uint16(window*256+j*8+7))
}
} }
off += length
seen += length + 2
} }
nsec = nsec[:ni]
fv.Set(reflect.ValueOf(nsec)) fv.Set(reflect.ValueOf(nsec))
off += blocks
} }
case reflect.Struct: case reflect.Struct:
off, ok = unpackStructValue(fv, msg, off) off, ok = unpackStructValue(fv, msg, off)