]> Cypherpunks repositories - gostls13.git/commitdiff
net: don't reject domain names with only numbers and hyphens
authorBrad Fitzpatrick <bradfitz@golang.org>
Mon, 24 Sep 2018 17:30:48 +0000 (17:30 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 24 Sep 2018 17:56:44 +0000 (17:56 +0000)
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 <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Gudger <igudger@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/net/dnsclient.go
src/net/dnsname_test.go

index e3524280b6aaff7ad96dc77b3dd86bc9c8c63bac..2c47bc413013f87a05b1a47209f448fb0bbaf13c 100644 (file)
@@ -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
index 806d8756cb5c5f0af4d8359ffb95456992ee7e1e..2964982311ce4b306494f26216168a45c0fe4859 100644 (file)
@@ -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},