summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2004-03-10 20:43:23 +0000
committerManuel Novoa III <mjn3@codepoet.org>2004-03-10 20:43:23 +0000
commit79248fe718689c31c3df3d24bfbc6f147bc345e7 (patch)
tree5ba7a3ef1a1355bd2e73a902cd5530df71675aa2 /libc
parent6994dd8083a0637876c43ff737f8c2dcf7735f83 (diff)
Bug fix: gethostbyname2_r would fail if /etc/host was missing.
Bug fix: gethostbyname_r checked errno without first setting it to a known value.
Diffstat (limited to 'libc')
-rw-r--r--libc/inet/resolv.c59
1 files changed, 38 insertions, 21 deletions
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index 592582133..0c9b52415 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -1860,20 +1860,26 @@ int gethostbyname_r(const char * name,
return EINVAL;
/* do /etc/hosts first */
- if ((i=__get_hosts_byname_r(name, AF_INET, result_buf,
- buf, buflen, result, h_errnop))==0)
- return i;
- switch (*h_errnop) {
- case HOST_NOT_FOUND:
- case NO_ADDRESS:
- break;
- case NETDB_INTERNAL:
- if (errno == ENOENT) {
- break;
- }
- /* else fall through */
- default:
+ {
+ int old_errno = errno; /* Save the old errno and reset errno */
+ __set_errno(0); /* to check for missing /etc/hosts. */
+
+ if ((i=__get_hosts_byname_r(name, AF_INET, result_buf,
+ buf, buflen, result, h_errnop))==0)
return i;
+ switch (*h_errnop) {
+ case HOST_NOT_FOUND:
+ case NO_ADDRESS:
+ break;
+ case NETDB_INTERNAL:
+ if (errno == ENOENT) {
+ break;
+ }
+ /* else fall through */
+ default:
+ return i;
+ }
+ __set_errno(old_errno);
}
DPRINTF("Nothing found in /etc/hosts\n");
@@ -1996,15 +2002,26 @@ int gethostbyname2_r(const char *name, int family,
return EINVAL;
/* do /etc/hosts first */
- if ((i=__get_hosts_byname_r(name, family, result_buf,
- buf, buflen, result, h_errnop))==0)
- return i;
- switch (*h_errnop) {
- case HOST_NOT_FOUND:
- case NO_ADDRESS:
- break;
- default:
+ {
+ int old_errno = errno; /* Save the old errno and reset errno */
+ __set_errno(0); /* to check for missing /etc/hosts. */
+
+ if ((i=__get_hosts_byname_r(name, AF_INET, result_buf,
+ buf, buflen, result, h_errnop))==0)
return i;
+ switch (*h_errnop) {
+ case HOST_NOT_FOUND:
+ case NO_ADDRESS:
+ break;
+ case NETDB_INTERNAL:
+ if (errno == ENOENT) {
+ break;
+ }
+ /* else fall through */
+ default:
+ return i;
+ }
+ __set_errno(old_errno);
}
DPRINTF("Nothing found in /etc/hosts\n");