]> Cypherpunks repositories - gostls13.git/commitdiff
net: use libresolv rules for ndots range and validation
authorDan Peterson <dpiddy@gmail.com>
Wed, 13 Jul 2016 16:35:35 +0000 (10:35 -0600)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 17 Aug 2016 15:20:24 +0000 (15:20 +0000)
BIND libresolv allows values from 0 to 15.

For invalid values and negative numbers, 0 is used.
For numbers greater than 15, 15 is used.

Fixes #15419

Change-Id: I1009bc119c3e87919bcb55a80a35532e9fc3ba52
Reviewed-on: https://go-review.googlesource.com/24901
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/net/dnsconfig_unix.go
src/net/dnsconfig_unix_test.go
src/net/testdata/invalid-ndots-resolv.conf [new file with mode: 0644]
src/net/testdata/large-ndots-resolv.conf [new file with mode: 0644]
src/net/testdata/negative-ndots-resolv.conf [new file with mode: 0644]

index b885813722536752e7674f57a11c2b8a4884fbde..683ae71812a65653a3dcc63558ca6ab94a79f8e9 100644 (file)
@@ -92,8 +92,10 @@ func dnsReadConfig(filename string) *dnsConfig {
                                switch {
                                case hasPrefix(s, "ndots:"):
                                        n, _, _ := dtoi(s[6:])
-                                       if n < 1 {
-                                               n = 1
+                                       if n < 0 {
+                                               n = 0
+                                       } else if n > 15 {
+                                               n = 15
                                        }
                                        conf.ndots = n
                                case hasPrefix(s, "timeout:"):
index 9fd6dbf982a22305b2118d1f8c3c925cba5f368d..89695c309935fe58e627073a4249e1b38df38481 100644 (file)
@@ -60,6 +60,36 @@ var dnsReadConfigTests = []struct {
                        search:   []string{"domain.local."},
                },
        },
+       {
+               name: "testdata/invalid-ndots-resolv.conf",
+               want: &dnsConfig{
+                       servers:  defaultNS,
+                       ndots:    0,
+                       timeout:  5 * time.Second,
+                       attempts: 2,
+                       search:   []string{"domain.local."},
+               },
+       },
+       {
+               name: "testdata/large-ndots-resolv.conf",
+               want: &dnsConfig{
+                       servers:  defaultNS,
+                       ndots:    15,
+                       timeout:  5 * time.Second,
+                       attempts: 2,
+                       search:   []string{"domain.local."},
+               },
+       },
+       {
+               name: "testdata/negative-ndots-resolv.conf",
+               want: &dnsConfig{
+                       servers:  defaultNS,
+                       ndots:    0,
+                       timeout:  5 * time.Second,
+                       attempts: 2,
+                       search:   []string{"domain.local."},
+               },
+       },
        {
                name: "testdata/openbsd-resolv.conf",
                want: &dnsConfig{
diff --git a/src/net/testdata/invalid-ndots-resolv.conf b/src/net/testdata/invalid-ndots-resolv.conf
new file mode 100644 (file)
index 0000000..084c164
--- /dev/null
@@ -0,0 +1 @@
+options ndots:invalid
\ No newline at end of file
diff --git a/src/net/testdata/large-ndots-resolv.conf b/src/net/testdata/large-ndots-resolv.conf
new file mode 100644 (file)
index 0000000..72968ee
--- /dev/null
@@ -0,0 +1 @@
+options ndots:16
\ No newline at end of file
diff --git a/src/net/testdata/negative-ndots-resolv.conf b/src/net/testdata/negative-ndots-resolv.conf
new file mode 100644 (file)
index 0000000..c11e0cc
--- /dev/null
@@ -0,0 +1 @@
+options ndots:-1
\ No newline at end of file