]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.3] net: Don't read beyond end of slice when parsing resolv.conf...
authorAndrew Gerrand <adg@golang.org>
Mon, 11 Aug 2014 23:31:36 +0000 (09:31 +1000)
committerAndrew Gerrand <adg@golang.org>
Mon, 11 Aug 2014 23:31:36 +0000 (09:31 +1000)
««« 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

src/pkg/net/dnsconfig_unix.go
src/pkg/net/testdata/resolv.conf

index af288253e09bacea861f751c779ae823c98035b2..db45716f124a155aa0519cd70ff6ad25c6e763f3 100644 (file)
@@ -75,19 +75,19 @@ func dnsReadConfig(filename string) (*dnsConfig, error) {
                        for i := 1; i < len(f); i++ {
                                s := f[i]
                                switch {
-                               case len(s) >= 6 && s[0:6] == "ndots:":
+                               case hasPrefix(s, "ndots:"):
                                        n, _, _ := dtoi(s, 6)
                                        if n < 1 {
                                                n = 1
                                        }
                                        conf.ndots = n
-                               case len(s) >= 8 && s[0:8] == "timeout:":
+                               case hasPrefix(s, "timeout:"):
                                        n, _, _ := dtoi(s, 8)
                                        if n < 1 {
                                                n = 1
                                        }
                                        conf.timeout = n
-                               case len(s) >= 8 && s[0:9] == "attempts:":
+                               case hasPrefix(s, "attempts:"):
                                        n, _, _ := dtoi(s, 9)
                                        if n < 1 {
                                                n = 1
@@ -103,3 +103,7 @@ func dnsReadConfig(filename string) (*dnsConfig, error) {
 
        return conf, nil
 }
+
+func hasPrefix(s, prefix string) bool {
+       return len(s) >= len(prefix) && s[:len(prefix)] == prefix
+}
index b5972e09c98bc8dc87b74515aa28f02673a71316..3841bbf90446bd99d29526fa63ec60e46f61f198 100644 (file)
@@ -3,3 +3,4 @@
 domain Home
 nameserver 192.168.1.1
 options ndots:5 timeout:10 attempts:3 rotate
+options attempts 3