[PATCH 03/12] batctl: netlink: don't format NULL extra_info in info_callback

Sven Eckelmann <[email protected]> Wed, 08 Jul 2026 22:00:09 +0200
Newsgroups org.open-mesh.lists.batman
Message-ID <[email protected]>
When asprintf() or strdup() fail to create the extra_info string,
info_callback() continues with extra_info set to NULL and passes it as
%s argument to the following asprintf(). Passing NULL to %s is
undefined behavior.

Fall back to an empty string when extra_info could not be allocated.

Fixes: d8dd1ff1a0fe ("batctl: Use netlink to replace some of debugfs")
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 cb65655..dd0275e 100644
--- a/netlink.c
+++ b/netlink.c
@@ -440,7 +440,8 @@ static int info_callback(struct nl_msg *msg, void *arg)
 			       mesh_name,
 			       mesh_mac[0], mesh_mac[1], mesh_mac[2],
 			       mesh_mac[3], mesh_mac[4], mesh_mac[5],
-			       algo_name, extra_info, extra_header);
+			       algo_name, extra_info ? extra_info : "",
+			       extra_header);
 		if (ret < 0)
 			opts->remaining_header = NULL;
 

-- 
2.47.3