mirror of
https://github.com/golang/go.git
synced 2025-11-09 21:21:03 +00:00
net: use libresolv rules for ndots range and validation
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>
This commit is contained in:
parent
04e76f295f
commit
2f73fe7a0d
5 changed files with 37 additions and 2 deletions
|
|
@ -92,8 +92,10 @@ func dnsReadConfig(filename string) *dnsConfig {
|
||||||
switch {
|
switch {
|
||||||
case hasPrefix(s, "ndots:"):
|
case hasPrefix(s, "ndots:"):
|
||||||
n, _, _ := dtoi(s[6:])
|
n, _, _ := dtoi(s[6:])
|
||||||
if n < 1 {
|
if n < 0 {
|
||||||
n = 1
|
n = 0
|
||||||
|
} else if n > 15 {
|
||||||
|
n = 15
|
||||||
}
|
}
|
||||||
conf.ndots = n
|
conf.ndots = n
|
||||||
case hasPrefix(s, "timeout:"):
|
case hasPrefix(s, "timeout:"):
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,36 @@ var dnsReadConfigTests = []struct {
|
||||||
search: []string{"domain.local."},
|
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",
|
name: "testdata/openbsd-resolv.conf",
|
||||||
want: &dnsConfig{
|
want: &dnsConfig{
|
||||||
|
|
|
||||||
1
src/net/testdata/invalid-ndots-resolv.conf
vendored
Normal file
1
src/net/testdata/invalid-ndots-resolv.conf
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
options ndots:invalid
|
||||||
1
src/net/testdata/large-ndots-resolv.conf
vendored
Normal file
1
src/net/testdata/large-ndots-resolv.conf
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
options ndots:16
|
||||||
1
src/net/testdata/negative-ndots-resolv.conf
vendored
Normal file
1
src/net/testdata/negative-ndots-resolv.conf
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
options ndots:-1
|
||||||
Loading…
Add table
Add a link
Reference in a new issue