Skip to content

Commit 5b3aafe

Browse files
committed
net: don't reject domain names with only numbers and hyphens
From #17659 (comment) ... > 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 <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Gudger <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 4039be0 commit 5b3aafe

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/net/dnsclient.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ func isDomainName(s string) bool {
7575
}
7676

7777
last := byte('.')
78-
ok := false // Ok once we've seen a letter.
78+
nonNumeric := false // true once we've seen a letter or hyphen
7979
partlen := 0
8080
for i := 0; i < len(s); i++ {
8181
c := s[i]
8282
switch {
8383
default:
8484
return false
8585
case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_':
86-
ok = true
86+
nonNumeric = true
8787
partlen++
8888
case '0' <= c && c <= '9':
8989
// fine
@@ -94,6 +94,7 @@ func isDomainName(s string) bool {
9494
return false
9595
}
9696
partlen++
97+
nonNumeric = true
9798
case c == '.':
9899
// Byte before dot cannot be dot, dash.
99100
if last == '.' || last == '-' {
@@ -110,7 +111,7 @@ func isDomainName(s string) bool {
110111
return false
111112
}
112113

113-
return ok
114+
return nonNumeric
114115
}
115116

116117
// absDomainName returns an absolute domain name which ends with a

src/net/dnsname_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var dnsNameTests = []dnsNameTest{
2222
{"foo.com", true},
2323
{"1foo.com", true},
2424
{"26.0.0.73.com", true},
25+
{"10-0-0-1", true},
2526
{"fo-o.com", true},
2627
{"fo1o.com", true},
2728
{"foo1.com", true},

0 commit comments

Comments
 (0)