From: Michael Hoisie Date: Wed, 27 Jan 2010 00:18:29 +0000 (-0800) Subject: net: fix segfault if /etc/hosts fails to open or doesn't exist X-Git-Tag: weekly.2010-01-27~19 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=dd97923d82488b21187608f831c46ec5e2fd9e8d;p=gostls13.git net: fix segfault if /etc/hosts fails to open or doesn't exist R=rsc CC=golang-dev, r https://golang.org/cl/194043 --- diff --git a/src/pkg/net/hosts.go b/src/pkg/net/hosts.go index 25af7968db..266ce3f370 100644 --- a/src/pkg/net/hosts.go +++ b/src/pkg/net/hosts.go @@ -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.