Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Sep 2015 09:19:08 +0000 (UTC)
From:      Hiroki Sato <hrs@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r287595 - head/lib/libc/net
Message-ID:  <201509090919.t899J80b096091@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201509090919.t899J80b096091>