b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [PATCH 3/6] alfred: don't drop the mesh interface name on OOM
Date: Fri, 31 Jul 2026 13:44:52 +0200	[thread overview]
Message-ID: <20260731-bugfixes-interfaces-v1-3-a148ca2f6688@narfation.org> (raw)
In-Reply-To: <20260731-bugfixes-interfaces-v1-0-a148ca2f6688@narfation.org>

unix_sock_change_bat_iface() freed the old mesh_iface and then assigned
the result of strdup() directly to globals->mesh_iface. When strdup()
failed the old name was already gone and mesh_iface was left NULL. But it
still reported a success success.

Duplicate the name into a temporary first and only replace the stored
pointer once the allocation succeeded.

Fixes: b96cc742ef3e ("alfred: introduce 'change batman-adv interface' IPC call")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 unix_sock.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/unix_sock.c b/unix_sock.c
index 64fde70..417b380 100644
--- a/unix_sock.c
+++ b/unix_sock.c
@@ -404,6 +404,7 @@ unix_sock_change_bat_iface(struct globals *globals,
 			   struct alfred_change_bat_iface_v0 *change_bat_iface,
 			   int client_sock)
 {
+	char *mesh_iface;
 	int ret = -1;
 	int len;
 
@@ -412,9 +413,13 @@ unix_sock_change_bat_iface(struct globals *globals,
 	if (len < (int)(sizeof(*change_bat_iface) - sizeof(change_bat_iface->header)))
 		goto err;
 
-	free(globals->mesh_iface);
 	change_bat_iface->bat_iface[sizeof(change_bat_iface->bat_iface) - 1] = '\0';
-	globals->mesh_iface = strdup(change_bat_iface->bat_iface);
+	mesh_iface = strdup(change_bat_iface->bat_iface);
+	if (!mesh_iface)
+		goto err;
+
+	free(globals->mesh_iface);
+	globals->mesh_iface = mesh_iface;
 
 	ret = 0;
 err:

-- 
2.47.3


  parent reply	other threads:[~2026-07-31 11:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31 11:44 [PATCH 0/6] alfred: interfaces: random fixes Sven Eckelmann
2026-07-31 11:44 ` [PATCH 1/6] alfred: fix off-by-one in client interface name length checks Sven Eckelmann
2026-07-31 11:44 ` [PATCH 2/6] alfred: update stored interface list on interface change Sven Eckelmann
2026-07-31 11:44 ` Sven Eckelmann [this message]
2026-07-31 11:44 ` [PATCH 4/6] alfred: keep the running interfaces when reconfiguration fails Sven Eckelmann
2026-07-31 11:44 ` [PATCH 5/6] alfred: Report failure when the client refuses to change interfaces Sven Eckelmann
2026-07-31 11:44 ` [PATCH 6/6] alfred: don't check the "none" on network interface change Sven Eckelmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260731-bugfixes-interfaces-v1-3-a148ca2f6688@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).