From b23c1519f14a2c93f7927996844522e3caede79c Mon Sep 17 00:00:00 2001 From: MatPerin Date: Thu, 14 Apr 2022 22:15:07 -0400 Subject: trafgen: Check pointer in ipv6 device address lookup function The getifaddrs function returns a linked list node for L2 even in the case of L3 interfaces (e.g. a TUN device), but with the pointer to the address structure set to NULL. This causes a segfault when trying to access the address family from it when such network interfaces are present in the system. The issue is solved by checking the validity of the pointer beforehand: if the address structure is present the address family can be fetched and the current iteration can go on safely, otherwise the node is skipped (as it is not linked to any address). Signed-off-by: Matteo Perin --- dev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev.c b/dev.c index 2ced495..a4f2b0e 100644 --- a/dev.c +++ b/dev.c @@ -82,6 +82,8 @@ static int __device_address6(const char *ifname, struct sockaddr_storage *ss) panic("Cannot get device addresses for IPv6!\n"); for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { + if (ifa->ifa_addr == NULL) + continue; family = ifa->ifa_addr->sa_family; if (family != AF_INET6) continue; -- cgit v1.2.3-54-g00ecf