From 690e447ea0a9cd488b953b95b3f1c86c8a526e03 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 1 Dec 2021 19:29:28 +0100 Subject: [PATCH] interfaces: on NetBSD, ifbic_req can use more than 64 bytes Therefore, allocate it dynamically. Fix #489. --- src/daemon/interfaces-bsd.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/daemon/interfaces-bsd.c b/src/daemon/interfaces-bsd.c index c8e466b0..d7d9c6c0 100644 --- a/src/daemon/interfaces-bsd.c +++ b/src/daemon/interfaces-bsd.c @@ -72,11 +72,19 @@ ifbsd_check_bridge(struct lldpd *cfg, struct interfaces_device_list *interfaces, struct interfaces_device *master) { - struct ifbreq req[64]; - struct ifbifconf bifc = { - .ifbic_len = sizeof(req), - .ifbic_req = req - }; + static size_t ifbic_len = 64; + struct ifbreq *req = NULL; + struct ifbifconf bifc = {}; + + retry_alloc: + if ((req = realloc(req, ifbic_len)) == NULL) { + log_warn("interfaces", "unable to allocate memory to query bridge %s", + master->name); + free(bifc.ifbic_req); + return; + } + bifc.ifbic_len = ifbic_len; + bifc.ifbic_req = req; #if defined HOST_OS_FREEBSD || defined HOST_OS_NETBSD || defined HOST_OS_OSX || defined HOST_OS_DRAGONFLY struct ifdrv ifd = { @@ -101,11 +109,9 @@ ifbsd_check_bridge(struct lldpd *cfg, #else # error Unsupported OS #endif - if (bifc.ifbic_len >= sizeof(req)) { - log_warnx("interfaces", - "%s is a bridge too big. Please, report the problem", - master->name); - return; + if (bifc.ifbic_len >= ifbic_len) { + ifbic_len = bifc.ifbic_len + 1; + goto retry_alloc; } for (int i = 0; i < bifc.ifbic_len / sizeof(*req); i++) { struct interfaces_device *slave = -- 2.39.5