From 784cdc2a0a4ce17f4ae227250d54312c4574847e Mon Sep 17 00:00:00 2001
From: millert <>
Date: Sun, 24 Jul 2005 18:47:59 +0000
Subject: 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@

---
 src/lib/libc/net/gethostnamadr.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

(limited to 'src/lib')

diff --git a/src/lib/libc/net/gethostnamadr.c b/src/lib/libc/net/gethostnamadr.c
index 626f9a6e65..70bff68fd6 100644
--- a/src/lib/libc/net/gethostnamadr.c
+++ b/src/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());
 }
 
-- 
cgit v1.2.3-55-g6feb