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

net: defend against broken getaddrinfo on Linux

getaddrinfo is supposed to set errno when it returns
EAI_SYSTEM, but sometimes it does not.

Fixes #6232.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13532045
This commit is contained in:
Russ Cox 2013-09-11 11:38:56 -04:00
parent 397ba2cb4a
commit 382738af51

View File

@ -99,6 +99,16 @@ func cgoLookupIPCNAME(name string) (addrs []IP, cname string, err error, complet
if gerrno == C.EAI_NONAME {
str = noSuchHost
} else if gerrno == C.EAI_SYSTEM {
if err == nil {
// err should not be nil, but sometimes getaddrinfo returns
// gerrno == C.EAI_SYSTEM with err == nil on Linux.
// The report claims that it happens when we have too many
// open files, so use syscall.EMFILE (too many open files in system).
// Most system calls would return ENFILE (too many open files),
// so at the least EMFILE should be easy to recognize if this
// comes up again. golang.org/issue/6232.
err = syscall.EMFILE
}
str = err.Error()
} else {
str = C.GoString(C.gai_strerror(gerrno))