1
0
mirror of https://github.com/golang/go synced 2024-11-22 00:44:39 -07:00

net: fix segfault if /etc/hosts fails to open or doesn't exist

R=rsc
CC=golang-dev, r
https://golang.org/cl/194043
This commit is contained in:
Michael Hoisie 2010-01-26 16:18:29 -08:00 committed by Russ Cox
parent 5f4c052e2d
commit dd97923d82

View 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.