diff mbox

[ovs-dev] netdev: verify ifa_addr is not NULL when iterating over getifaddrs

Message ID 1459372337-21102-1-git-send-email-cascardo@redhat.com
State Accepted
Headers show

Commit Message

Thadeu Lima de Souza Cascardo March 30, 2016, 9:12 p.m. UTC
Some point-to-point devices like TUN devices will not have an address, and while
iterating over ifaddrs, its ifa_addr will be NULL. This patch fixes a crash when
starting ovs-vswitchd on a system with such a device.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>
Fixes: a8704b502785 ("tunneling: Handle multiple ip address for given device.")
Cc: Pravin B Shelar <pshelar@ovn.org>
---
 lib/netdev.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Comments

Ben Pfaff March 31, 2016, midnight UTC | #1
On Wed, Mar 30, 2016 at 06:12:17PM -0300, Thadeu Lima de Souza Cascardo wrote:
> Some point-to-point devices like TUN devices will not have an address, and while
> iterating over ifaddrs, its ifa_addr will be NULL. This patch fixes a crash when
> starting ovs-vswitchd on a system with such a device.
> 
> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>
> Fixes: a8704b502785 ("tunneling: Handle multiple ip address for given device.")
> Cc: Pravin B Shelar <pshelar@ovn.org>

Thanks, applied to master.
diff mbox

Patch

diff --git a/lib/netdev.c b/lib/netdev.c
index 95fdbc7..928f46f 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -1882,12 +1882,14 @@  netdev_get_addrs(const char dev[], struct in6_addr **paddr,
     }
 
     for (ifa = if_addr_list; ifa; ifa = ifa->ifa_next) {
-        int family;
+        if (ifa->ifa_addr != NULL) {
+            int family;
 
-        family = ifa->ifa_addr->sa_family;
-        if (family == AF_INET || family == AF_INET6) {
-            if (!strncmp(ifa->ifa_name, dev, IFNAMSIZ)) {
-                cnt++;
+            family = ifa->ifa_addr->sa_family;
+            if (family == AF_INET || family == AF_INET6) {
+                if (!strncmp(ifa->ifa_name, dev, IFNAMSIZ)) {
+                    cnt++;
+                }
             }
         }
     }
@@ -1901,7 +1903,7 @@  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)) {
+        if (strncmp(ifa->ifa_name, dev, IFNAMSIZ) || ifa->ifa_addr == NULL) {
             continue;
         }