All of lore.kernel.org
 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 2/8] alfred: vis: keep interface names always in heap
Date: Tue, 28 Jul 2026 18:01:31 +0200	[thread overview]
Message-ID: <20260728-bugfixes-vis-v1-2-2540447c8a67@narfation.org> (raw)
In-Reply-To: <20260728-bugfixes-vis-v1-0-2540447c8a67@narfation.org>

The interface pointer in globals was used to store an address in .rodata or
in on the heap. This makes the handling of the allocation/deallocation
hard. At the same time, nothing checked for allocations problems. An
allocation error could cause an hard-to-debug problem later when trying to
calculate the ifindex.

Adjust the code to always allocate the string as an heap object to simplify
the handling.

Fixes: 2e3e312f7757 ("alfred: add vis")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 vis/vis.c | 12 +++++++++++-
 vis/vis.h |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/vis/vis.c b/vis/vis.c
index d635798..97c6093 100644
--- a/vis/vis.c
+++ b/vis/vis.c
@@ -1058,10 +1058,15 @@ static struct globals *vis_init(int argc, char *argv[])
 	memset(globals, 0, sizeof(*globals));
 
 	globals->opmode = OPMODE_CLIENT;
-	globals->interface = "bat0";
 	globals->vis_format = FORMAT_DOT;
 	globals->unix_path = ALFRED_SOCK_PATH_DEFAULT;
 
+	globals->interface = strdup("bat0");
+	if (!globals->interface) {
+		perror("strdup");
+		return NULL;
+	}
+
 	while ((opt = getopt_long(argc, argv, "shf:i:vu:", long_options,
 				  &opt_ind)) != -1) {
 		switch (opt) {
@@ -1081,7 +1086,12 @@ static struct globals *vis_init(int argc, char *argv[])
 			}
 			break;
 		case 'i':
+			free(globals->interface);
 			globals->interface = strdup(optarg);
+			if (!globals->interface) {
+				perror("strdup");
+				return NULL;
+			}
 			break;
 		case 'u':
 			globals->unix_path = optarg;
diff --git a/vis/vis.h b/vis/vis.h
index e257c45..d3486f9 100644
--- a/vis/vis.h
+++ b/vis/vis.h
@@ -73,7 +73,7 @@ struct vis_list_entry {
 	 (vis_data)->entries_n * sizeof(struct vis_entry))
 
 struct globals {
-	const char *interface;
+	char *interface;
 	enum opmode opmode;
 	enum vis_format vis_format;
 	uint8_t buf[65536];

-- 
2.47.3


  parent reply	other threads:[~2026-07-28 19:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28 16:01 [PATCH 0/8] alfred: vis: random fixes Sven Eckelmann
2026-07-28 16:01 ` [PATCH 1/8] alfred: vis: reject too long unix socket paths Sven Eckelmann
2026-07-28 16:01 ` Sven Eckelmann [this message]
2026-07-28 16:01 ` [PATCH 3/8] alfred: vis: return query_rtnl_link error on failed send Sven Eckelmann
2026-07-28 16:01 ` [PATCH 4/8] alfred: vis: handle short reads on the unix socket Sven Eckelmann
2026-07-28 16:01 ` [PATCH 5/8] alfred: vis: report failures while reading the answer Sven Eckelmann
2026-07-28 16:01 ` [PATCH 6/8] alfred: vis: don't drop the rest of the answer for a bogus dataset Sven Eckelmann
2026-07-28 16:01 ` [PATCH 7/8] alfred: vis: fix jsondoc output for nodes without vis entries Sven Eckelmann
2026-07-28 16:01 ` [PATCH 8/8] alfred: vis: skip originators with unresolvable hard interface 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=20260728-bugfixes-vis-v1-2-2540447c8a67@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.