added additional checks on structure returned by getifaddrs()

This commit is contained in:
Thomas Bernard 2012-01-02 11:12:52 +01:00
parent 63a83f8a0a
commit 8f68347464
2 changed files with 8 additions and 3 deletions

View File

@ -2,6 +2,7 @@ $Id: Changelog.txt,v 1.242 2011/11/18 11:21:20 nanard Exp $
2012/01/02: 2012/01/02:
Fixing netfilter/iptables_*.sh scripts for new ifconfig output format. Fixing netfilter/iptables_*.sh scripts for new ifconfig output format.
getifaddr.c: added additional checks on structure returned by getifaddrs()
2011/11/18: 2011/11/18:
avoid infinite loop in SendResp_upnphttp() in case of error avoid infinite loop in SendResp_upnphttp() in case of error

View File

@ -1,4 +1,4 @@
/* $Id: getifaddr.c,v 1.11 2011/05/15 08:59:27 nanard Exp $ */ /* $Id: getifaddr.c,v 1.12 2012/01/02 10:08:42 nanard Exp $ */
/* MiniUPnP project /* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2011 Thomas Bernard * (c) 2006-2011 Thomas Bernard
@ -74,8 +74,10 @@ getifaddr(const char * ifname, char * buf, int len)
} }
for(ife = ifap; ife; ife = ife->ifa_next) for(ife = ifap; ife; ife = ife->ifa_next)
{ {
/* skip other interfaces */ /* skip other interfaces if one was specified */
if(0 != strcmp(ifname, ife->ifa_name)) if(ifname && (0 != strcmp(ifname, ife->ifa_name)))
continue;
if(ife->ifa_addr == NULL)
continue; continue;
switch(ife->ifa_addr->sa_family) switch(ife->ifa_addr->sa_family)
{ {
@ -121,6 +123,8 @@ find_ipv6_addr(const char * ifname,
/* skip other interfaces if one was specified */ /* skip other interfaces if one was specified */
if(ifname && (0 != strcmp(ifname, ife->ifa_name))) if(ifname && (0 != strcmp(ifname, ife->ifa_name)))
continue; continue;
if(ife->ifa_addr == NULL)
continue;
if(ife->ifa_addr->sa_family == AF_INET6) if(ife->ifa_addr->sa_family == AF_INET6)
{ {
addr = (const struct sockaddr_in6 *)ife->ifa_addr; addr = (const struct sockaddr_in6 *)ife->ifa_addr;