mirror of https://github.com/golang/go.git
net: allow single dot in resolv.conf search statement
A single dot in a search statement doesn't affect DNS lookup, so just ignore it and a syntax error. Fixes #54124 Change-Id: Idd43bd34c5c16af50cba51f0b6e24f992eec6e57 Reviewed-on: https://go-review.googlesource.com/c/go/+/423875 Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
ee833ed72e
commit
55ecc3a886
|
|
@ -64,9 +64,13 @@ func dnsReadConfig(filename string) *dnsConfig {
|
|||
}
|
||||
|
||||
case "search": // set search path to given servers
|
||||
conf.search = make([]string, len(f)-1)
|
||||
for i := 0; i < len(conf.search); i++ {
|
||||
conf.search[i] = ensureRooted(f[i+1])
|
||||
conf.search = make([]string, 0, len(f)-1)
|
||||
for i := 1; i < len(f); i++ {
|
||||
name := ensureRooted(f[i])
|
||||
if name == "." {
|
||||
continue
|
||||
}
|
||||
conf.search = append(conf.search, name)
|
||||
}
|
||||
|
||||
case "options": // magic options
|
||||
|
|
|
|||
|
|
@ -52,6 +52,16 @@ var dnsReadConfigTests = []struct {
|
|||
attempts: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "testdata/search-single-dot-resolv.conf",
|
||||
want: &dnsConfig{
|
||||
servers: []string{"8.8.8.8:53"},
|
||||
search: []string{},
|
||||
ndots: 1,
|
||||
timeout: 5 * time.Second,
|
||||
attempts: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "testdata/empty-resolv.conf",
|
||||
want: &dnsConfig{
|
||||
|
|
@ -166,6 +176,9 @@ func TestDNSReadConfig(t *testing.T) {
|
|||
getHostname = func() (string, error) { return "host.domain.local", nil }
|
||||
|
||||
for _, tt := range dnsReadConfigTests {
|
||||
if len(tt.want.search) == 0 {
|
||||
tt.want.search = append(tt.want.search, dnsDefaultSearch()...)
|
||||
}
|
||||
conf := dnsReadConfig(tt.name)
|
||||
if conf.err != nil {
|
||||
t.Fatal(conf.err)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
# /etc/resolv.conf
|
||||
|
||||
domain localdomain
|
||||
search .
|
||||
nameserver 8.8.8.8
|
||||
Loading…
Reference in New Issue