From: Siddhesh Poyarekar Date: Mon, 19 Nov 2012 07:31:43 +0000 (+0530) Subject: Return EAI_SYSTEM if we're out of file descriptors X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20ac5d44837b82c064dfabd3646ec1f4f6826263;p=thirdparty%2Fglibc.git Return EAI_SYSTEM if we're out of file descriptors Resolves BZ #14719. Conflicts: ChangeLog NEWS --- diff --git a/ChangeLog b/ChangeLog index 6fc9ebcf8ab..bef6c5c780c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2012-11-19 Siddhesh Poyarekar + + [BZ #14719] + * nss/getXXbyYY_r.c (INTERNAL (REENTRANT_NAME)): Set h_errno to + NETDB_INTERNAL when NSS_STATUS_UNAVAIL. + * resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname3_r): Set + h_errno to NETDB_INTERNAL when errno is EMFILE or ENFILE. + (_nss_dns_gethostbyname4_r): Likewise. + * sysdeps/posix/getaddrinfo.c (gaih_inet): Set result to + EAI_SYSTEM if NSS_STATUS_UNAVAIL. + 2013-09-25 Adhemerval Zanella * sysdeps/powerpc/powerpc64/stackguard-macros.h (POINTER_CHK_GUARD: diff --git a/NEWS b/NEWS index aa9544fa303..a9f0b50cf55 100644 --- a/NEWS +++ b/NEWS @@ -9,8 +9,8 @@ Version 2.16.1 * The following bugs are resolved with this release: - 6530, 14195, 14547, 14459, 14476, 14562, 14621, 14648, 14699, 14756, 14831, - 15078, 15754, 15755, 16072, 16431, 16617, 17048, 17137, 17187, 17325, + 6530, 14195, 14547, 14459, 14476, 14562, 14621, 14648, 14699, 14719, 14756, + 14831, 15078, 15754, 15755, 16072, 16431, 16617, 17048, 17137, 17187, 17325, 17625, 17630. * CVE-2104-7817 The wordexp function could ignore the WRDE_NOCMD flag diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c index d197c9be175..50c04068f23 100644 --- a/nss/getXXbyYY_r.c +++ b/nss/getXXbyYY_r.c @@ -276,7 +276,12 @@ done: #endif *result = status == NSS_STATUS_SUCCESS ? resbuf : NULL; #ifdef NEED_H_ERRNO - if (status != NSS_STATUS_SUCCESS && ! any_service) + if (status == NSS_STATUS_UNAVAIL) + /* Either we failed to lookup the functions or the functions themselves + had a system error. Set NETDB_INTERNAL here to let the caller know + that the errno may have the real reason for failure. */ + *h_errnop = NETDB_INTERNAL; + else if (status != NSS_STATUS_SUCCESS && !any_service) /* We were not able to use any service. */ *h_errnop = NO_RECOVERY; #endif diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c index a924d40844a..00caff5a2e8 100644 --- a/resolv/nss_dns/dns-host.c +++ b/resolv/nss_dns/dns-host.c @@ -203,6 +203,11 @@ _nss_dns_gethostbyname3_r (const char *name, int af, struct hostent *result, status = NSS_STATUS_TRYAGAIN; h_errno = TRY_AGAIN; break; + /* System has run out of file descriptors. */ + case EMFILE: + case ENFILE: + h_errno = NETDB_INTERNAL; + /* Fall through. */ case ECONNREFUSED: case ETIMEDOUT: status = NSS_STATUS_UNAVAIL; @@ -315,14 +320,26 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat, &ans2p, &nans2p, &resplen2); if (n < 0) { - if (errno == ESRCH) + switch (errno) { + case ESRCH: status = NSS_STATUS_TRYAGAIN; h_errno = TRY_AGAIN; + break; + /* System has run out of file descriptors. */ + case EMFILE: + case ENFILE: + h_errno = NETDB_INTERNAL; + /* Fall through. */ + case ECONNREFUSED: + case ETIMEDOUT: + status = NSS_STATUS_UNAVAIL; + break; + default: + status = NSS_STATUS_NOTFOUND; + break; } - else - status = (errno == ECONNREFUSED - ? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND); + *herrnop = h_errno; if (h_errno == TRY_AGAIN) *errnop = EAGAIN; diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 0146eb95b98..dd851305545 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -1058,6 +1058,12 @@ gaih_inet (const char *name, const struct gaih_service *service, _res.options |= old_res_options & RES_USE_INET6; + if (status == NSS_STATUS_UNAVAIL) + { + result = GAIH_OKIFUNSPEC | -EAI_SYSTEM; + goto free_and_return; + } + if (no_data != 0 && no_inet6_data != 0) { /* If both requests timed out report this. */