Skip to content

Commit

Permalink
lib: net: Avoid comparing the content of unassigned IPs in net_ip_cmp().
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanbosch authored and sirainen committed Mar 12, 2018
1 parent 050b6ae commit 7b8354f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lib/net.c
Expand Up @@ -59,10 +59,15 @@ int net_ip_cmp(const struct ip_addr *ip1, const struct ip_addr *ip2)
if (ip1->family != ip2->family)
return ip1->family - ip2->family;

if (ip1->family == AF_INET6)
switch (ip1->family) {
case AF_INET6:
return memcmp(&ip1->u.ip6, &ip2->u.ip6, sizeof(ip1->u.ip6));

return memcmp(&ip1->u.ip4, &ip2->u.ip4, sizeof(ip1->u.ip4));
case AF_INET:
return memcmp(&ip1->u.ip4, &ip2->u.ip4, sizeof(ip1->u.ip4));
default:
break;
}
return 0;
}

unsigned int net_ip_hash(const struct ip_addr *ip)
Expand Down

0 comments on commit 7b8354f

Please sign in to comment.