From: Mateusz Poliwczak Date: Sat, 7 Feb 2026 10:03:17 +0000 (+0100) Subject: net: always set the servers field to defaultNS X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=30d5c1b0572f7d021def277097df6a21f300995e;p=gostls13.git net: always set the servers field to defaultNS When the field is parsed from a file, it would never have len(servers) == 0, lets enforce that and update test cases where we had it wrong. Change-Id: I7fa6ebcf63b9fe20fbbf791113ca948d6a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/743020 Auto-Submit: Michael Pratt Reviewed-by: Junyang Shao LUCI-TryBot-Result: Go LUCI Reviewed-by: Damien Neil Reviewed-by: Sean Liao --- diff --git a/src/net/conf_test.go b/src/net/conf_test.go index 075253cbc1..e3dbb37f19 100644 --- a/src/net/conf_test.go +++ b/src/net/conf_test.go @@ -142,7 +142,7 @@ func TestConfHostLookupOrder(t *testing.T) { c: &conf{ goos: "openbsd", }, - resolv: &dnsConfig{lookup: []string{"bind", "file"}}, + resolv: &dnsConfig{servers: defaultNS, lookup: []string{"bind", "file"}}, hostTests: []nssHostTest{ {"google.com", "myhostname", hostLookupDNSFiles}, {"foo.local", "myhostname", hostLookupDNSFiles}, @@ -153,7 +153,7 @@ func TestConfHostLookupOrder(t *testing.T) { c: &conf{ goos: "openbsd", }, - resolv: &dnsConfig{lookup: []string{"file", "bind"}}, + resolv: &dnsConfig{servers: defaultNS, lookup: []string{"file", "bind"}}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupFilesDNS}}, }, { @@ -161,7 +161,7 @@ func TestConfHostLookupOrder(t *testing.T) { c: &conf{ goos: "openbsd", }, - resolv: &dnsConfig{lookup: []string{"bind"}}, + resolv: &dnsConfig{servers: defaultNS, lookup: []string{"bind"}}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupDNS}}, }, { @@ -169,7 +169,7 @@ func TestConfHostLookupOrder(t *testing.T) { c: &conf{ goos: "openbsd", }, - resolv: &dnsConfig{lookup: []string{"file"}}, + resolv: &dnsConfig{servers: defaultNS, lookup: []string{"file"}}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupFiles}}, }, { @@ -177,7 +177,7 @@ func TestConfHostLookupOrder(t *testing.T) { c: &conf{ goos: "openbsd", }, - resolv: &dnsConfig{lookup: []string{"file", "bind", "yp"}}, + resolv: &dnsConfig{servers: defaultNS, lookup: []string{"file", "bind", "yp"}}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupCgo}}, }, { @@ -185,7 +185,7 @@ func TestConfHostLookupOrder(t *testing.T) { c: &conf{ goos: "openbsd", }, - resolv: &dnsConfig{lookup: []string{"file", "foo"}}, + resolv: &dnsConfig{servers: defaultNS, lookup: []string{"file", "foo"}}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupCgo}}, }, { @@ -193,7 +193,7 @@ func TestConfHostLookupOrder(t *testing.T) { c: &conf{ goos: "openbsd", }, - resolv: &dnsConfig{lookup: nil}, + resolv: &dnsConfig{servers: defaultNS, lookup: nil}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupDNSFiles}}, }, { diff --git a/src/net/dnsclient_unix.go b/src/net/dnsclient_unix.go index 4d7b2fb5ea..fc671053f5 100644 --- a/src/net/dnsclient_unix.go +++ b/src/net/dnsclient_unix.go @@ -393,6 +393,16 @@ func (conf *resolverConfig) tryUpdate(name string) { conf.initOnce.Do(conf.init) dc := conf.dnsConfig.Load() + + // Currently we should never have a config that does not have any + // available servers to query, since in such cases the servers field + // is set to [defaultNS], see dnsReadConfig. + // This assertion main purpose is for testing, such that we never set + // the mocked dnsConfig in such way. + if len(dc.servers) == 0 { + panic("unreachable") + } + if dc.noReload { return }