From dd97923d82488b21187608f831c46ec5e2fd9e8d Mon Sep 17 00:00:00 2001 From: Michael Hoisie Date: Tue, 26 Jan 2010 16:18:29 -0800 Subject: [PATCH] net: fix segfault if /etc/hosts fails to open or doesn't exist R=rsc CC=golang-dev, r https://golang.org/cl/194043 --- src/pkg/net/hosts.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pkg/net/hosts.go b/src/pkg/net/hosts.go index 25af7968dbb..266ce3f3700 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.