mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-02 16:01:27 +01:00
util/dnsname: increase maxNameLength to account for trailing dot
Fixes #17788 Signed-off-by: Fran Bull <fran@tailscale.com>
This commit is contained in:
parent
e8d2f96449
commit
27a0168cdc
@ -14,7 +14,7 @@ const (
|
||||
// maxLabelLength is the maximum length of a label permitted by RFC 1035.
|
||||
maxLabelLength = 63
|
||||
// maxNameLength is the maximum length of a DNS name.
|
||||
maxNameLength = 253
|
||||
maxNameLength = 254
|
||||
)
|
||||
|
||||
// A FQDN is a fully-qualified DNS name or name suffix.
|
||||
|
||||
@ -59,6 +59,38 @@ func TestFQDN(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFQDNTooLong(t *testing.T) {
|
||||
// RFC 1035 says a dns name has a max size of 255 octets, and is represented as labels of len+ASCII chars so
|
||||
// example.com
|
||||
// is represented as
|
||||
// 7example3com0
|
||||
// which is to say that if we have a trailing dot then the dots cancel out all the len bytes except the first and
|
||||
// we can accept 254 chars.
|
||||
|
||||
// This name is max length
|
||||
name := "aaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaa.example.com."
|
||||
if len(name) != 254 {
|
||||
t.Fatalf("name should be 254 chars including trailing . (len is %d)", len(name))
|
||||
}
|
||||
got, err := ToFQDN(name)
|
||||
if err != nil {
|
||||
t.Fatalf("want: error to end with \"is too long to be a DNS name\", got: %v", err)
|
||||
}
|
||||
if string(got) != name {
|
||||
t.Fatalf("want: %s, got: %s", name, got)
|
||||
}
|
||||
|
||||
// This name is too long
|
||||
name = "x" + name
|
||||
got, err = ToFQDN(name)
|
||||
if got != "" {
|
||||
t.Fatalf("want: \"\", got: %s", got)
|
||||
}
|
||||
if err == nil || !strings.HasSuffix(err.Error(), "is too long to be a DNS name") {
|
||||
t.Fatalf("want: error to end with \"is too long to be a DNS name\", got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFQDNContains(t *testing.T) {
|
||||
tests := []struct {
|
||||
a, b string
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user