[ovs-dev] [PATCH] netdev: fix crash when ifa_netmask is null

Ben Pfaff blp at ovn.org
Wed Jul 12 04:55:54 UTC 2017


On Tue, Jul 04, 2017 at 08:52:57AM +0800, Haifeng Lin wrote:
> The ifa_netmask is null when failed to call ioctl
> in getifaddrs
> 
> Signed-off-by: Haifeng Lin <haifeng.lin at huawei.com>

Thanks for figuring this out.

What does it mean if ifa_netmask is null?  Does it mean that the address
should be ignored entirely?  The manpage for getifaddrs doesn't say.
And what about for IPv4 addresses?

Maybe the right fix would be this:

diff --git a/lib/netdev.c b/lib/netdev.c
index 26e87a2ee2ec..68003a829f27 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -1967,7 +1967,8 @@ netdev_get_addrs(const char dev[], struct in6_addr **paddr,
     for (ifa = if_addr_list; ifa; ifa = ifa->ifa_next) {
         int family;
 
-        if (strncmp(ifa->ifa_name, dev, IFNAMSIZ) || ifa->ifa_addr == NULL) {
+        if (strncmp(ifa->ifa_name, dev, IFNAMSIZ)
+            || !ifa->ifa_addr || !ifa->ifa_netmask) {
             continue;
         }
 
What do you think?

Thanks,

Ben.


More information about the dev mailing list