summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2005-07-24 18:48:00 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2005-07-24 18:48:00 +0000
commit11b081130cd5c55ec1bed389a2bc9c980f600157 (patch)
tree67f1299918e51f245b7e6878beead82d676c68bd
parent25c1094c68d52081bd0278e3840e52b84b65b877 (diff)
In _gethtent() ignore host.h_length if it is set to 0. Previously
we only ignored it if host.h_addrtype was AF_UNSPEC. Set host.h_length to 0 in _gethtbyname2() since that function does not take a length argument. Problem found by jaredy@
-rw-r--r--lib/libc/net/gethostnamadr.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c
index 626f9a6e65b..70bff68fd6f 100644
--- a/lib/libc/net/gethostnamadr.c
+++ b/lib/libc/net/gethostnamadr.c
@@ -48,7 +48,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.64 2005/07/23 04:15:49 jaredy Exp $";
+static const char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.65 2005/07/24 18:47:59 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -832,12 +832,10 @@ _gethtent(void)
goto again;
}
/* if this is not something we're looking for, skip it. */
- if (host.h_addrtype != AF_UNSPEC) {
- if (host.h_addrtype != af)
- goto again;
- if (host.h_length != len)
- goto again;
- }
+ if (host.h_addrtype != AF_UNSPEC && host.h_addrtype != af)
+ goto again;
+ if (host.h_length != 0 && host.h_length != len)
+ goto again;
h_addr_ptrs[0] = (char *)host_addr;
h_addr_ptrs[1] = NULL;
host.h_addr_list = h_addr_ptrs;
@@ -877,11 +875,9 @@ _gethtbyname2(const char *name, int af)
char **cp;
host.h_addrtype = af;
-
+ host.h_length = 0;
_sethtent(0);
while ((p = _gethtent())) {
- if (p->h_addrtype != af)
- continue;
if (strcasecmp(p->h_name, name) == 0)
break;
for (cp = p->h_aliases; *cp != 0; cp++)
@@ -1084,6 +1080,7 @@ struct hostent *
gethostent(void)
{
host.h_addrtype = AF_UNSPEC;
+ host.h_length = 0;
return (_gethtent());
}