[ovs-dev] [PATCH] netdev: verify ifa_addr is not NULL when iterating over getifaddrs
Thadeu Lima de Souza Cascardo
cascardo at redhat.com
Wed Mar 30 21:12:17 UTC 2016
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 at redhat.com>
Fixes: a8704b502785 ("tunneling: Handle multiple ip address for given device.")
Cc: Pravin B Shelar <pshelar at ovn.org>
---
lib/netdev.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
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;
}
--
2.5.0
More information about the dev
mailing list