diff options
author | hrs <hrs@FreeBSD.org> | 2015-09-09 09:19:07 +0000 |
---|---|---|
committer | hrs <hrs@FreeBSD.org> | 2015-09-09 09:19:07 +0000 |
commit | 0e29b6e367d93b2951cabcff2e2adff60a4629a4 (patch) | |
tree | 690984c457dde505c4626a3c890ff1d9aef06e91 /lib/libc | |
parent | 3676d092ee30e57e7065d9c60c07e755902144ec (diff) | |
download | FreeBSD-src-0e29b6e367d93b2951cabcff2e2adff60a4629a4.zip FreeBSD-src-0e29b6e367d93b2951cabcff2e2adff60a4629a4.tar.gz |
- Fix SIGSEGV when sa == NULL. NULL check in getnameinfo_inet()
did not work as expected.
- Simplify afdl table lookup.
MFC after: 3 days
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/net/getnameinfo.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/lib/libc/net/getnameinfo.c b/lib/libc/net/getnameinfo.c index f83d0e2..d7e7971 100644 --- a/lib/libc/net/getnameinfo.c +++ b/lib/libc/net/getnameinfo.c @@ -78,6 +78,8 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen, 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 *sa, socklen_t salen, 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; |