Error: change a whole bunch error messages' prefix (#1657)

* Error: change a whole bunch error messages' prefix

Long ago we started using 'bad ...' as the error messages, the "dns:"
prefix is used for panic's not in normal errors, remove are replace a
whole bunch of "dns:" with "bad ..."

Signed-off-by: Miek Gieben <miek@miek.nl>

* Error: change a whole bunch error messages' prefix

Long ago we started using 'bad ...' as the error messages, the "dns:"
prefix is used for panic's not in normal errors, remove are replace a
whole bunch of "dns:" with "bad ..."

Signed-off-by: Miek Gieben <miek@miek.nl>

* Use "bad" here too and use terminoloy from Msg struct

Extra instead of Ar count

Signed-off-by: Miek Gieben <miek@miek.nl>

---------

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben 2025-07-09 14:25:16 +02:00 committed by GitHub
parent 186ccfbcd9
commit 09e0436f4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 50 additions and 50 deletions

22
edns.go
View File

@ -317,30 +317,30 @@ func (e *EDNS0_SUBNET) pack() ([]byte, error) {
// "dig" sets AddressFamily to 0 if SourceNetmask is also 0
// We might don't need to complain either
if e.SourceNetmask != 0 {
return nil, errors.New("dns: bad address family")
return nil, errors.New("bad address family")
}
case 1:
if e.SourceNetmask > net.IPv4len*8 {
return nil, errors.New("dns: bad netmask")
return nil, errors.New("bad netmask")
}
if len(e.Address.To4()) != net.IPv4len {
return nil, errors.New("dns: bad address")
return nil, errors.New("bad address")
}
ip := e.Address.To4().Mask(net.CIDRMask(int(e.SourceNetmask), net.IPv4len*8))
needLength := (e.SourceNetmask + 8 - 1) / 8 // division rounding up
b = append(b, ip[:needLength]...)
case 2:
if e.SourceNetmask > net.IPv6len*8 {
return nil, errors.New("dns: bad netmask")
return nil, errors.New("bad netmask")
}
if len(e.Address) != net.IPv6len {
return nil, errors.New("dns: bad address")
return nil, errors.New("bad address")
}
ip := e.Address.Mask(net.CIDRMask(int(e.SourceNetmask), net.IPv6len*8))
needLength := (e.SourceNetmask + 8 - 1) / 8 // division rounding up
b = append(b, ip[:needLength]...)
default:
return nil, errors.New("dns: bad address family")
return nil, errors.New("bad address family")
}
return b, nil
}
@ -357,25 +357,25 @@ func (e *EDNS0_SUBNET) unpack(b []byte) error {
// "dig" sets AddressFamily to 0 if SourceNetmask is also 0
// It's okay to accept such a packet
if e.SourceNetmask != 0 {
return errors.New("dns: bad address family")
return errors.New("bad address family")
}
e.Address = net.IPv4(0, 0, 0, 0)
case 1:
if e.SourceNetmask > net.IPv4len*8 || e.SourceScope > net.IPv4len*8 {
return errors.New("dns: bad netmask")
return errors.New("bad netmask")
}
addr := make(net.IP, net.IPv4len)
copy(addr, b[4:])
e.Address = addr.To16()
case 2:
if e.SourceNetmask > net.IPv6len*8 || e.SourceScope > net.IPv6len*8 {
return errors.New("dns: bad netmask")
return errors.New("bad netmask")
}
addr := make(net.IP, net.IPv6len)
copy(addr, b[4:])
e.Address = addr
default:
return errors.New("dns: bad address family")
return errors.New("bad address family")
}
return nil
}
@ -720,7 +720,7 @@ func (e *EDNS0_TCP_KEEPALIVE) unpack(b []byte) error {
case 2:
e.Timeout = binary.BigEndian.Uint16(b)
default:
return fmt.Errorf("dns: length mismatch, want 0/2 but got %d", len(b))
return fmt.Errorf("length mismatch, want 0/2 but got %d", len(b))
}
return nil
}

18
msg.go
View File

@ -1123,21 +1123,21 @@ func unpackQuestion(msg []byte, off int) (Question, int, error) {
)
q.Name, off, err = UnpackDomainName(msg, off)
if err != nil {
return q, off, fmt.Errorf("question.Name: %w", err)
return q, off, fmt.Errorf("bad question name: %w", err)
}
if off == len(msg) {
return q, off, nil
}
q.Qtype, off, err = unpackUint16(msg, off)
if err != nil {
return q, off, fmt.Errorf("question.Qtype: %w", err)
return q, off, fmt.Errorf("bad question qtype: %w", err)
}
if off == len(msg) {
return q, off, nil
}
q.Qclass, off, err = unpackUint16(msg, off)
if err != nil {
return q, off, fmt.Errorf("question.Qclass: %w", err)
return q, off, fmt.Errorf("bad question qclass: %w", err)
}
if off == len(msg) {
@ -1182,27 +1182,27 @@ func unpackMsgHdr(msg []byte, off int) (Header, int, error) {
)
dh.Id, off, err = unpackUint16(msg, off)
if err != nil {
return dh, off, fmt.Errorf("header.Id: %w", err)
return dh, off, fmt.Errorf("bad header id: %w", err)
}
dh.Bits, off, err = unpackUint16(msg, off)
if err != nil {
return dh, off, fmt.Errorf("header.Bits: %w", err)
return dh, off, fmt.Errorf("bad header bits: %w", err)
}
dh.Qdcount, off, err = unpackUint16(msg, off)
if err != nil {
return dh, off, fmt.Errorf("header.Qdcount: %w", err)
return dh, off, fmt.Errorf("bad header question count: %w", err)
}
dh.Ancount, off, err = unpackUint16(msg, off)
if err != nil {
return dh, off, fmt.Errorf("header.Ancount: %w", err)
return dh, off, fmt.Errorf("bad header answer count: %w", err)
}
dh.Nscount, off, err = unpackUint16(msg, off)
if err != nil {
return dh, off, fmt.Errorf("header.Nscount: %w", err)
return dh, off, fmt.Errorf("bad header ns count: %w", err)
}
dh.Arcount, off, err = unpackUint16(msg, off)
if err != nil {
return dh, off, fmt.Errorf("header.Arcount: %w", err)
return dh, off, fmt.Errorf("bad header extra count: %w", err)
}
return dh, off, nil
}

View File

@ -335,7 +335,7 @@ func (srv *Server) ListenAndServe() error {
return srv.serveTCP(l)
case "tcp-tls", "tcp4-tls", "tcp6-tls":
if srv.TLSConfig == nil || (len(srv.TLSConfig.Certificates) == 0 && srv.TLSConfig.GetCertificate == nil) {
return errors.New("dns: neither Certificates nor GetCertificate set in Config")
return errors.New("neither Certificates nor GetCertificate set in config")
}
network := strings.TrimSuffix(srv.Net, "-tls")
l, err := listenTCP(network, addr, srv.ReusePort, srv.ReuseAddr)

58
svcb.go
View File

@ -298,7 +298,7 @@ func (s *SVCBMandatory) pack() ([]byte, error) {
func (s *SVCBMandatory) unpack(b []byte) error {
if len(b)%2 != 0 {
return errors.New("dns: svcbmandatory: value length is not a multiple of 2")
return errors.New("bad svcbmandatory: value length is not a multiple of 2")
}
codes := make([]SVCBKey, 0, len(b)/2)
for i := 0; i < len(b); i += 2 {
@ -395,10 +395,10 @@ func (s *SVCBAlpn) pack() ([]byte, error) {
b := make([]byte, 0, 10*len(s.Alpn))
for _, e := range s.Alpn {
if e == "" {
return nil, errors.New("dns: svcbalpn: empty alpn-id")
return nil, errors.New("bad svcbalpn: empty alpn-id")
}
if len(e) > 255 {
return nil, errors.New("dns: svcbalpn: alpn-id too long")
return nil, errors.New("bad svcbalpn: alpn-id too long")
}
b = append(b, byte(len(e)))
b = append(b, e...)
@ -413,7 +413,7 @@ func (s *SVCBAlpn) unpack(b []byte) error {
length := int(b[i])
i++
if i+length > len(b) {
return errors.New("dns: svcbalpn: alpn array overflowing")
return errors.New("bad svcbalpn: alpn array overflowing")
}
alpn = append(alpn, string(b[i:i+length]))
i += length
@ -433,13 +433,13 @@ func (s *SVCBAlpn) parse(b string) error {
for p := 0; p < len(b); {
c, q := nextByte(b, p)
if q == 0 {
return errors.New("dns: svcbalpn: unterminated escape")
return errors.New("bad svcbalpn: unterminated escape")
}
p += q
// If we find a comma, we have finished reading an alpn.
if c == ',' {
if len(a) == 0 {
return errors.New("dns: svcbalpn: empty protocol identifier")
return errors.New("bad svcbalpn: empty protocol identifier")
}
alpn = append(alpn, string(a))
a = []byte{}
@ -449,10 +449,10 @@ func (s *SVCBAlpn) parse(b string) error {
if c == '\\' {
dc, dq := nextByte(b, p)
if dq == 0 {
return errors.New("dns: svcbalpn: unterminated escape decoding comma-separated list")
return errors.New("bad svcbalpn: unterminated escape decoding comma-separated list")
}
if dc != '\\' && dc != ',' {
return errors.New("dns: svcbalpn: bad escaped character decoding comma-separated list")
return errors.New("bad svcbalpn: bad escaped character decoding comma-separated list")
}
p += dq
c = dc
@ -461,7 +461,7 @@ func (s *SVCBAlpn) parse(b string) error {
}
// Add the final alpn.
if len(a) == 0 {
return errors.New("dns: svcbalpn: last protocol identifier empty")
return errors.New("bad svcbalpn: last protocol identifier empty")
}
s.Alpn = append(alpn, string(a))
return nil
@ -499,14 +499,14 @@ func (*SVCBNoDefaultAlpn) len() int { return 0 }
func (*SVCBNoDefaultAlpn) unpack(b []byte) error {
if len(b) != 0 {
return errors.New("dns: svcbnodefaultalpn: no-default-alpn must have no value")
return errors.New("bad svcbnodefaultalpn: no-default-alpn must have no value")
}
return nil
}
func (*SVCBNoDefaultAlpn) parse(b string) error {
if b != "" {
return errors.New("dns: svcbnodefaultalpn: no-default-alpn must have no value")
return errors.New("bad svcbnodefaultalpn: no-default-alpn must have no value")
}
return nil
}
@ -529,7 +529,7 @@ func (s *SVCBPort) copy() SVCBKeyValue { return &SVCBPort{s.Port} }
func (s *SVCBPort) unpack(b []byte) error {
if len(b) != 2 {
return errors.New("dns: svcbport: port length is not exactly 2 octets")
return errors.New("bad svcbport: port length is not exactly 2 octets")
}
s.Port = binary.BigEndian.Uint16(b)
return nil
@ -544,7 +544,7 @@ func (s *SVCBPort) pack() ([]byte, error) {
func (s *SVCBPort) parse(b string) error {
port, err := strconv.ParseUint(b, 10, 16)
if err != nil {
return errors.New("dns: svcbport: port out of range")
return errors.New("bad svcbport: port out of range")
}
s.Port = uint16(port)
return nil
@ -577,7 +577,7 @@ func (s *SVCBIPv4Hint) pack() ([]byte, error) {
for _, e := range s.Hint {
x := e.To4()
if x == nil {
return nil, errors.New("dns: svcbipv4hint: expected ipv4, hint is ipv6")
return nil, errors.New("bad svcbipv4hint: expected ipv4, hint is ipv6")
}
b = append(b, x...)
}
@ -586,7 +586,7 @@ func (s *SVCBIPv4Hint) pack() ([]byte, error) {
func (s *SVCBIPv4Hint) unpack(b []byte) error {
if len(b) == 0 || len(b)%4 != 0 {
return errors.New("dns: svcbipv4hint: ipv4 address byte array length is not a multiple of 4")
return errors.New("bad svcbipv4hint: ipv4 address byte array length is not a multiple of 4")
}
b = cloneSlice(b)
x := make([]net.IP, 0, len(b)/4)
@ -611,10 +611,10 @@ func (s *SVCBIPv4Hint) String() string {
func (s *SVCBIPv4Hint) parse(b string) error {
if b == "" {
return errors.New("dns: svcbipv4hint: empty hint")
return errors.New("bad svcbipv4hint: empty hint")
}
if strings.Contains(b, ":") {
return errors.New("dns: svcbipv4hint: expected ipv4, got ipv6")
return errors.New("bad svcbipv4hint: expected ipv4, got ipv6")
}
hint := make([]net.IP, 0, strings.Count(b, ",")+1)
@ -623,7 +623,7 @@ func (s *SVCBIPv4Hint) parse(b string) error {
e, b, _ = strings.Cut(b, ",")
ip := net.ParseIP(e).To4()
if ip == nil {
return errors.New("dns: svcbipv4hint: bad ip")
return errors.New("bad svcbipv4hint: bad ip")
}
hint = append(hint, ip)
}
@ -671,7 +671,7 @@ func (s *SVCBECHConfig) unpack(b []byte) error {
func (s *SVCBECHConfig) parse(b string) error {
x, err := fromBase64([]byte(b))
if err != nil {
return errors.New("dns: svcbech: bad base64 ech")
return errors.New("bad svcbech: bad base64 ech")
}
s.ECH = x
return nil
@ -699,7 +699,7 @@ func (s *SVCBIPv6Hint) pack() ([]byte, error) {
b := make([]byte, 0, 16*len(s.Hint))
for _, e := range s.Hint {
if len(e) != net.IPv6len || e.To4() != nil {
return nil, errors.New("dns: svcbipv6hint: expected ipv6, hint is ipv4")
return nil, errors.New("bad svcbipv6hint: expected ipv6, hint is ipv4")
}
b = append(b, e...)
}
@ -708,14 +708,14 @@ func (s *SVCBIPv6Hint) pack() ([]byte, error) {
func (s *SVCBIPv6Hint) unpack(b []byte) error {
if len(b) == 0 || len(b)%16 != 0 {
return errors.New("dns: svcbipv6hint: ipv6 address byte array length not a multiple of 16")
return errors.New("bas svcbipv6hint: ipv6 address byte array length not a multiple of 16")
}
b = cloneSlice(b)
x := make([]net.IP, 0, len(b)/16)
for i := 0; i < len(b); i += 16 {
ip := net.IP(b[i : i+16])
if ip.To4() != nil {
return errors.New("dns: svcbipv6hint: expected ipv6, got ipv4")
return errors.New("bad svcbipv6hint: expected ipv6, got ipv4")
}
x = append(x, ip)
}
@ -736,7 +736,7 @@ func (s *SVCBIPv6Hint) String() string {
func (s *SVCBIPv6Hint) parse(b string) error {
if b == "" {
return errors.New("dns: svcbipv6hint: empty hint")
return errors.New("bad svcbipv6hint: empty hint")
}
hint := make([]net.IP, 0, strings.Count(b, ",")+1)
@ -745,10 +745,10 @@ func (s *SVCBIPv6Hint) parse(b string) error {
e, b, _ = strings.Cut(b, ",")
ip := net.ParseIP(e)
if ip == nil {
return errors.New("dns: svcbipv6hint: bad ip")
return errors.New("bad svcbipv6hint: bad ip")
}
if ip.To4() != nil {
return errors.New("dns: svcbipv6hint: expected ipv6, got ipv4-mapped-ipv6")
return errors.New("bad svcbipv6hint: expected ipv6, got ipv4-mapped-ipv6")
}
hint = append(hint, ip)
}
@ -800,7 +800,7 @@ func (s *SVCBDoHPath) unpack(b []byte) error {
func (s *SVCBDoHPath) parse(b string) error {
template, err := svcbParseParam(b)
if err != nil {
return fmt.Errorf("dns: svcbdohpath: %w", err)
return fmt.Errorf("bad svcbdohpath: %w", err)
}
s.Template = string(template)
return nil
@ -838,14 +838,14 @@ func (*SVCBOhttp) len() int { return 0 }
func (*SVCBOhttp) unpack(b []byte) error {
if len(b) != 0 {
return errors.New("dns: svcbotthp: svcbotthp must have no value")
return errors.New("bad svcbotthp: svcbotthp must have no value")
}
return nil
}
func (*SVCBOhttp) parse(b string) error {
if b != "" {
return errors.New("dns: svcbotthp: svcbotthp must have no value")
return errors.New("bad svcbotthp: svcbotthp must have no value")
}
return nil
}
@ -878,7 +878,7 @@ func (s *SVCBLocal) unpack(b []byte) error {
func (s *SVCBLocal) parse(b string) error {
data, err := svcbParseParam(b)
if err != nil {
return fmt.Errorf("dns: svcblocal: svcb private/experimental key %w", err)
return fmt.Errorf("bad svcblocal: svcb private/experimental key %w", err)
}
s.Data = data
return nil