]> Cypherpunks repositories - gostls13.git/commitdiff
net: fix segfault if /etc/hosts fails to open or doesn't exist
authorMichael Hoisie <hoisie@gmail.com>
Wed, 27 Jan 2010 00:18:29 +0000 (16:18 -0800)
committerRuss Cox <rsc@golang.org>
Wed, 27 Jan 2010 00:18:29 +0000 (16:18 -0800)
R=rsc
CC=golang-dev, r
https://golang.org/cl/194043

src/pkg/net/hosts.go

index 25af7968dbb01d219d65891778e4a14df2fd8f98..266ce3f3700400c9625b6e2bcf54d806912545c3 100644 (file)
@@ -30,7 +30,9 @@ func readHosts() {
        if len(hosts.data) == 0 || hosts.time+cacheMaxAge <= now || hosts.path != hp {
                hs := make(map[string][]string)
                var file *file
-               file, _ = open(hp)
+               if file, _ = open(hp); file == nil {
+                       return
+               }
                for line, ok := file.readLine(); ok; line, ok = file.readLine() {
                        if i := byteIndex(line, '#'); i >= 0 {
                                // Discard comments.