Skip to content

Commit

Permalink
netdev: check for NULL fields in netdev_get_addrs
Browse files Browse the repository at this point in the history
When the interfaces list is retrieved through getiffaddrs(), there
might be elements with iface_name set to NULL.

This patch checks ifa_name to be not NULL before comparing it to the
actual device name in the loop that calculates how many interfaces
exist with that same name.

Also, this patch checks that ifa_netmask is not NULL for coherence
with the existing code so that it doesn't allocate more memory
than needed if this field is NULL.

Note, that these checks are already being done later in the function
so it should be done in both places.

Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Lance Richardson <lrichard@redhat.com>
  • Loading branch information
danalsan authored and blp committed Aug 8, 2017
1 parent 33118cf commit 31840b2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/netdev.c
Expand Up @@ -1890,7 +1890,7 @@ netdev_get_addrs(const char dev[], struct in6_addr **paddr,
}

for (ifa = if_addr_list; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_addr != NULL) {
if (ifa->ifa_addr && ifa->ifa_name && ifa->ifa_netmask) {
int family;

family = ifa->ifa_addr->sa_family;
Expand Down

0 comments on commit 31840b2

Please sign in to comment.