[PATCH 19/28] batctl: netlink: always 0-terminate hardif name

Sven Eckelmann <[email protected]> Sun, 21 Jun 2026 16:24:09 +0200
Newsgroups org.open-mesh.lists.batman
Message-ID <[email protected]>
The kernel should not send non-0 terminated interface name name or an
interface name larger than IFNAMSIZ. Just to be on the safe side, still
force the last byte to the 0-delimiter.

Fixes: 426e48c8d9ca ("batctl: ping: Get outgoing ifname from netlink")
Signed-off-by: Sven Eckelmann <[email protected]>
---
 netlink.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/netlink.c b/netlink.c
index 3a1c3a5..14100c3 100644
--- a/netlink.c
+++ b/netlink.c
@@ -822,7 +822,8 @@ static int get_nexthop_netlink_cb(struct nl_msg *msg, void *arg)
 
 	if (attrs[BATADV_ATTR_HARD_IFNAME]) {
 		ifname = nla_get_string(attrs[BATADV_ATTR_HARD_IFNAME]);
-		strncpy(opts->ifname, ifname, IFNAMSIZ);
+		strncpy(opts->ifname, ifname, IFNAMSIZ - 1);
+		opts->ifname[IFNAMSIZ - 1] = '\0';
 	} else {
 		/* compatibility for Linux < 5.14/batman-adv < 2021.2 */
 		ifname = if_indextoname(index, opts->ifname);

-- 
2.47.3