svn commit: r287729 - stable/10/lib/libc/net

Hiroki Sato hrs at FreeBSD.org
Sun Sep 13 01:31:18 UTC 2015


Author: hrs
Date: Sun Sep 13 01:31:17 2015
New Revision: 287729
URL: https://svnweb.freebsd.org/changeset/base/287729

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

Modified:
  stable/10/lib/libc/net/getnameinfo.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/net/getnameinfo.c
==============================================================================
--- stable/10/lib/libc/net/getnameinfo.c	Sun Sep 13 00:08:04 2015	(r287728)
+++ stable/10/lib/libc/net/getnameinfo.c	Sun Sep 13 01:31:17 2015	(r287729)
@@ -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-stable mailing list