Skip to content

Commit 1798bb2

Browse files
committed
[release-branch.go1.3] net: Don't read beyond end of slice when parsing resolv.conf options.
««« CL 102470046 / 5207b394de96 net: Don't read beyond end of slice when parsing resolv.conf options. Fixes #8252. LGTM=adg R=ruiu, josharian, adg CC=golang-codereviews https://golang.org/cl/102470046 »»» TBR=rsc CC=golang-codereviews https://golang.org/cl/124140043
1 parent 0752bc8 commit 1798bb2

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/pkg/net/dnsconfig_unix.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,19 @@ func dnsReadConfig(filename string) (*dnsConfig, error) {
7575
for i := 1; i < len(f); i++ {
7676
s := f[i]
7777
switch {
78-
case len(s) >= 6 && s[0:6] == "ndots:":
78+
case hasPrefix(s, "ndots:"):
7979
n, _, _ := dtoi(s, 6)
8080
if n < 1 {
8181
n = 1
8282
}
8383
conf.ndots = n
84-
case len(s) >= 8 && s[0:8] == "timeout:":
84+
case hasPrefix(s, "timeout:"):
8585
n, _, _ := dtoi(s, 8)
8686
if n < 1 {
8787
n = 1
8888
}
8989
conf.timeout = n
90-
case len(s) >= 8 && s[0:9] == "attempts:":
90+
case hasPrefix(s, "attempts:"):
9191
n, _, _ := dtoi(s, 9)
9292
if n < 1 {
9393
n = 1
@@ -103,3 +103,7 @@ func dnsReadConfig(filename string) (*dnsConfig, error) {
103103

104104
return conf, nil
105105
}
106+
107+
func hasPrefix(s, prefix string) bool {
108+
return len(s) >= len(prefix) && s[:len(prefix)] == prefix
109+
}

src/pkg/net/testdata/resolv.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
domain Home
44
nameserver 192.168.1.1
55
options ndots:5 timeout:10 attempts:3 rotate
6+
options attempts 3

0 commit comments

Comments
 (0)