Skip to contentSkip to conversation

batctl: Minor netlink related bug fixes

PATCH New Sven Eckelmann 1 participant 3 messages Aug 3, 2025

lore
Share & tools
lore
#0 lore raw

cover batctl: Minor netlink related bug fixes

The code to get the hard interface name for an even was accidentally checking for BATADV_ATTR_MESH_IFNAME instead of BATADV_ATTR_HARD_IFNAME. As result, the fallback code was always used when BATADV_ATTR_MESH_IFNAME would have not been available.

Luckily, at the moment, BATADV_ATTR_HARD_IFNAME is always available when BATADV_ATTR_MESH_IFNAME is set BATADV_CMD_SET_HARDIF events.

The opts.remaining_header string is alocated before the netlink callback object is created. But the callback object allocation can fail and the function will return in this case. To fix this, either the string buffer must be freed in this case or the opts.remaining_header allocation can simply be moved to a later point.

---
Sven Eckelmann (2):
batctl: event: Fix direct parsing on hardif for set_hardif
batctl: Avoid memory leak in print_routing_algos

 event.c        | 2 +-
 routing_algo.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

---
base-commit: e690b207753a122eb30b8eaf8b504c81b9178b79
change-id: 20250803-various-bugfixes-090544ff7199

Best regards,

Signature · 1 line
Sven Eckelmann <[email protected]>
#1 lore raw

PATCH 1/2 batctl: event: Fix direct parsing on hardif for set_hardif

The code to get the hard interface name for an even was accidentally checking for BATADV_ATTR_MESH_IFNAME instead of BATADV_ATTR_HARD_IFNAME. As result, the fallback code was always used when BATADV_ATTR_MESH_IFNAME would have not been available.

Luckily, at the moment, BATADV_ATTR_HARD_IFNAME is always available when BATADV_ATTR_MESH_IFNAME is set BATADV_CMD_SET_HARDIF events.

Fixes d12322eeb361 ("batctl: event: Get ifname from netlink message")
---
 event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
event.c +1 -1
index 33764e3..85234ce 100644
@@ -319,7 +319,7 @@ static void event_parse_set_hardif(struct nlattr **attrs)
 			return;
 	}
 
-	if (attrs[BATADV_ATTR_MESH_IFNAME]) {
+	if (attrs[BATADV_ATTR_HARD_IFNAME]) {
 		hardif_name = nla_get_string(attrs[BATADV_ATTR_HARD_IFNAME]);
 	} else {
 		/* compatibility for Linux < 5.14/batman-adv < 2021.2 */
Signature · 1 line
2.47.2
#2 lore raw

PATCH 2/2 batctl: Avoid memory leak in print_routing_algos

In reply to Sven Eckelmann

The opts.remaining_header string is alocated before the netlink callback object is created. But the callback object allocation can fail and the function will return in this case. To fix this, either the string buffer must be freed in this case or the opts.remaining_header allocation can simply be moved to a later point.

Fixes 0a14f8800dac ("batctl: Handle nl_cb_alloc errors")
---
 routing_algo.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
routing_algo.c +2 -2
index 5aa4597..c3f4580 100644
@@ -95,12 +95,12 @@ static int print_routing_algos(struct state *state)
 	nl_send_auto_complete(state->sock, msg);
 	nlmsg_free(msg);
 
-	opts.remaining_header = strdup("Available routing algorithms:\n");
-
 	cb = nl_cb_alloc(NL_CB_DEFAULT);
 	if (!cb)
 		return -ENOMEM;
 
+	opts.remaining_header = strdup("Available routing algorithms:\n");
+
 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, netlink_print_common_cb,
 		  &opts);
 	nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, netlink_stop_callback, NULL);
Signature · 1 line
2.47.2