make sure p->ifa_addr is not NULL before using it

This commit is contained in:
jscipione 2016-08-22 11:59:29 -07:00 committed by Kurtis Rader
parent b0184f1476
commit a872d9c299

View file

@ -931,7 +931,7 @@ static bool get_mac_address(unsigned char macaddr[MAC_ADDRESS_MAX_LEN],
if (getifaddrs(&ifap) == 0) {
for (const ifaddrs *p = ifap; p; p = p->ifa_next) {
if (p->ifa_addr->sa_family == AF_LINK) {
if (p->ifa_addr && p->ifa_addr->sa_family == AF_LINK) {
if (p->ifa_name && p->ifa_name[0] &&
!strcmp((const char *)p->ifa_name, interface)) {
const sockaddr_dl &sdl = *reinterpret_cast<sockaddr_dl *>(p->ifa_addr);