From 5b3aafe2b51b5455a42a65cca1cf0e8393970c03 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 24 Sep 2018 17:30:48 +0000 Subject: [PATCH] net: don't reject domain names with only numbers and hyphens From https://github.com/golang/go/issues/17659#issuecomment-423113606 ... > In kubernetes , isDomainName reject Pods "A Record" "pod-ip-address", > for example: "172-17-0-16", as RFC 3696 section 2 requires > "top-level domain names not be all-numeric", but this example has > three hyphen, so I think it should not be reject. Updates #17659 Change-Id: Ibd8ffb9473d69c45c91525953c09c6749233ca20 Reviewed-on: https://go-review.googlesource.com/136900 Run-TryBot: Brad Fitzpatrick Reviewed-by: Ian Lance Taylor Reviewed-by: Ian Gudger TryBot-Result: Gobot Gobot --- src/net/dnsclient.go | 7 ++++--- src/net/dnsname_test.go | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/net/dnsclient.go b/src/net/dnsclient.go index e3524280b6..2c47bc4130 100644 --- a/src/net/dnsclient.go +++ b/src/net/dnsclient.go @@ -75,7 +75,7 @@ func isDomainName(s string) bool { } last := byte('.') - ok := false // Ok once we've seen a letter. + nonNumeric := false // true once we've seen a letter or hyphen partlen := 0 for i := 0; i < len(s); i++ { c := s[i] @@ -83,7 +83,7 @@ func isDomainName(s string) bool { default: return false case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_': - ok = true + nonNumeric = true partlen++ case '0' <= c && c <= '9': // fine @@ -94,6 +94,7 @@ func isDomainName(s string) bool { return false } partlen++ + nonNumeric = true case c == '.': // Byte before dot cannot be dot, dash. if last == '.' || last == '-' { @@ -110,7 +111,7 @@ func isDomainName(s string) bool { return false } - return ok + return nonNumeric } // absDomainName returns an absolute domain name which ends with a diff --git a/src/net/dnsname_test.go b/src/net/dnsname_test.go index 806d8756cb..2964982311 100644 --- a/src/net/dnsname_test.go +++ b/src/net/dnsname_test.go @@ -22,6 +22,7 @@ var dnsNameTests = []dnsNameTest{ {"foo.com", true}, {"1foo.com", true}, {"26.0.0.73.com", true}, + {"10-0-0-1", true}, {"fo-o.com", true}, {"fo1o.com", true}, {"foo1.com", true},