svn commit: r287595 - head/lib/libc/net

Hiroki Sato hrs at FreeBSD.org
Wed Sep 9 09:19:08 UTC 2015


Author: hrs
Date: Wed Sep  9 09:19:07 2015
New Revision: 287595
URL: https://svnweb.freebsd.org/changeset/base/287595

Log:
  - Fix SIGSEGV when sa == NULL.  NULL check in getnameinfo_inet()
    did not work as expected.
  
  - Simplify afdl table lookup.
  
  MFC after:	3 days

Modified:
  head/lib/libc/net/getnameinfo.c

Modified: head/lib/libc/net/getnameinfo.c
==============================================================================
--- head/lib/libc/net/getnameinfo.c	Wed Sep  9 08:52:39 2015	(r287594)
+++ head/lib/libc/net/getnameinfo.c	Wed Sep  9 09:19:07 2015	(r287595)
@@ -78,6 +78,8 @@ getnameinfo(const struct sockaddr *sa, s
     char *host, size_t hostlen, char *serv, size_t servlen,
     int flags)
 {
+	if (sa == NULL)
+		return (EAI_FAIL);
 
 	switch (sa->sa_family) {
 	case AF_INET:
@@ -124,25 +126,19 @@ getnameinfo_inet(const struct sockaddr *
 	struct servent *sp;
 	struct hostent *hp;
 	u_short port;
-	int family, i;
 	const char *addr;
 	u_int32_t v4a;
 	int h_error;
 	char numserv[512];
 	char numaddr[512];
 
-	if (sa == NULL)
-		return EAI_FAIL;
-
-	family = sa->sa_family;
-	for (i = 0; afdl[i].a_af; i++)
-		if (afdl[i].a_af == family) {
-			afd = &afdl[i];
-			goto found;
-		}
-	return EAI_FAMILY;
+	for (afd = &afdl[0]; afd->a_af > 0; afd++) {
+		if (afd->a_af == sa->sa_family)
+			break;
+	}
+	if (afd->a_af == 0)
+		return (EAI_FAMILY);
 
- found:
 	if (salen != afd->a_socklen)
 		return EAI_FAIL;
 


More information about the svn-src-all mailing list