miekg / dns

DNS library in Go
https://miek.nl/2014/august/16/go-dns-package
BSD 3-Clause "New" or "Revised" License
7.99k stars 1.13k forks source link

NewRR accepts invalid RR string #1549

Closed mattias-p closed 6 months ago

mattias-p commented 6 months ago

When I run this program I get the following output.

package main

import (
    "fmt"

    "github.com/miekg/dns"
)

func main() {
    rr, err := dns.NewRR(". 4294967295 IN NS")
    if err != nil {
        panic(err)
    }   

    fmt.Printf("%s\n", rr)

    buf := make([]byte, dns.Len(rr))

    n, err := dns.PackRR(rr, buf, 0, nil, false)
    if err != nil {
        panic(err)
    }

    fmt.Printf("%v\n", buf[0:n])
}
.   4294967295  IN  NS  
[0 0 2 0 1 255 255 255 255 0 0]

The call to NewRR happily returns an NS RR with empty RDATA. I would have expected NewRR to return an error instead. Is this behavior intentional or is it a bug?

miekg commented 6 months ago

except this isn't invalid if you take dynamic updates into consideration

mattias-p commented 6 months ago

Good point. Thanks for clarifying.