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

58
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) nsec := make([]uint16, 0)
ni := 0 length := 0
window := int(msg[off]) window := 0
blocks := int(msg[off+1]) seen := 2
if off+blocks > lenmsg { for seen < rdlength {
window = int(msg[off])
length = int(msg[off+1])
if length == 0 || length > 32 {
//fmt.Fprintf(os.Stderr, "dns: overflow unpacking NSEC") //fmt.Fprintf(os.Stderr, "dns: overflow unpacking NSEC")
return lenmsg, false println("illegal length value", length)
}
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 break
// return lenmsg, false
} }
off += 2 off += 2
for j := 0; j < blocks; j++ { for j := 0; j < length; j++ {
b := msg[off+j] b := msg[off+j]
// Check the bits one by one, and set the type // Check the bits one by one, and set the type
if b&0x80 == 0x80 { if b&0x80 == 0x80 {
nsec[ni] = uint16(window*256 + j*8 + 0) nsec = append(nsec, uint16(window*256+j*8+0))
ni++
} }
if b&0x40 == 0x40 { if b&0x40 == 0x40 {
nsec[ni] = uint16(window*256 + j*8 + 1) nsec = append(nsec, uint16(window*256+j*8+1))
ni++
} }
if b&0x20 == 0x20 { if b&0x20 == 0x20 {
nsec[ni] = uint16(window*256 + j*8 + 2) nsec = append(nsec, uint16(window*256+j*8+2))
ni++
} }
if b&0x10 == 0x10 { if b&0x10 == 0x10 {
nsec[ni] = uint16(window*256 + j*8 + 3) nsec = append(nsec, uint16(window*256+j*8+3))
ni++
} }
if b&0x8 == 0x8 { if b&0x8 == 0x8 {
nsec[ni] = uint16(window*256 + j*8 + 4) nsec = append(nsec, uint16(window*256+j*8+4))
ni++
} }
if b&0x4 == 0x4 { if b&0x4 == 0x4 {
nsec[ni] = uint16(window*256 + j*8 + 5) nsec = append(nsec, uint16(window*256+j*8+5))
ni++
} }
if b&0x2 == 0x2 { if b&0x2 == 0x2 {
nsec[ni] = uint16(window*256 + j*8 + 6) nsec = append(nsec, uint16(window*256+j*8+6))
ni++
} }
if b&0x1 == 0x1 { if b&0x1 == 0x1 {
nsec[ni] = uint16(window*256 + j*8 + 7) nsec = append(nsec, uint16(window*256+j*8+7))
ni++
} }
} }
nsec = nsec[:ni] off += length
seen += length + 2
}
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)