]> Cypherpunks repositories - gostls13.git/commitdiff
net: always set the servers field to defaultNS
authorMateusz Poliwczak <mpoliwczak34@gmail.com>
Sat, 7 Feb 2026 10:03:17 +0000 (11:03 +0100)
committerGopher Robot <gobot@golang.org>
Thu, 12 Feb 2026 20:05:51 +0000 (12:05 -0800)
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 <mpratt@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
src/net/conf_test.go
src/net/dnsclient_unix.go

index 075253cbc13dd9055368adac006f493e4a5945a7..e3dbb37f19e6c13398df469472ebd7f834706788 100644 (file)
@@ -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}},
                },
                {
index 4d7b2fb5ea4de27d9b4a88f01cec4c7bf57026f1..fc671053f559a87c455c70186889657a75847ae5 100644 (file)
@@ -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
        }