Add test to zero rdata (for dyn updates)

This triggerd a bunch of failures, the most important one
is the packing and zero length domain name now works.
This commit is contained in:
Miek Gieben 2013-08-26 21:11:24 -07:00
parent cb9ec711f5
commit fdcdc6dbf6
4 changed files with 14 additions and 7 deletions

View File

@ -3,6 +3,8 @@
* Support for on-the-fly-signing or check how to do it
* Test all rdata packing with zero rdata -- allowed for dynamic updates
* Actually mimic net/ ? Dial. Read/Write ?
- if I want this i need to work on something else than \*Client, because a single client
can have multiple oustanding qeuries
* Ratelimiting? server side (rrl)
* Ratelimiting? client side

View File

@ -243,12 +243,12 @@ func TestToRFC3597(t *testing.T) {
func TestNoRdata(t *testing.T) {
data := make([]byte, 1024)
for typ, _ := range TypeToString {
r := rr_mk[typ]()
for typ, fn := range rr_mk {
r := fn()
*r.Header() = RR_Header{Name: "miek.nl.", Rrtype: typ, Class: ClassINET, Ttl: 3600}
_, e := PackRR(r, data, 0, nil, false)
if e != nil {
t.Logf("Failed to pack rdata zero RR %d: %s\n", typ, e.Error())
t.Logf("Failed to pack rdata zero RR %s: %s\n", TypeToString[typ], e.Error())
t.Fail()
}
}

9
msg.go
View File

@ -214,8 +214,11 @@ var RcodeToString = map[int]string{
func PackDomainName(s string, msg []byte, off int, compression map[string]int, compress bool) (off1 int, err error) {
lenmsg := len(msg)
ls := len(s)
if ls == 0 { // Ok, for instance when dealing with update RR without any rdata.
return off, nil
}
// If not fully qualified, error out
if ls == 0 || s[ls-1] != '.' {
if s[ls-1] != '.' {
return lenmsg, ErrFqdn
}
// Each dot ends a segment of the name.
@ -468,7 +471,9 @@ func packStructValue(val reflect.Value, msg []byte, off int, compression map[str
return lenmsg, &Error{err: "overflow packing a"}
}
case `dns:"aaaa"`:
// fv.Len TODO(mg) dynamic updates?
if fv.Len() == 0 {
break
}
if fv.Len() > net.IPv6len || off+fv.Len() > lenmsg {
return lenmsg, &Error{err: "overflow packing aaaa"}
}

View File

@ -884,8 +884,8 @@ func (rr *TA) len() int {
type TALINK struct {
Hdr RR_Header
PreviousName string `dns:"domain"`
NextName string `dns:"domain"`
PreviousName string `dns:"domain-name"`
NextName string `dns:"domain-name"`
}
func (rr *TALINK) Header() *RR_Header { return &rr.Hdr }