summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatPerin <matteoperin1302@gmail.com>2022-04-14 22:15:07 -0400
committerTobias Klauser <tobias.klauser@gmail.com>2022-04-22 11:20:09 +0200
commitb23c1519f14a2c93f7927996844522e3caede79c (patch)
tree438a08989277c943cc3abba6223f4afc116cae14
parentf0187ac5c6b9ee8d600521a88e4c8a482744171c (diff)
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 <matteoperin1302@gmail.com>
-rw-r--r--dev.c2
1 files changed, 2 insertions, 0 deletions
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;