[PATCH 1/8] alfred: vis: reject too long unix socket paths

Sven Eckelmann <[email protected]> Tue, 28 Jul 2026 18:01:30 +0200
Newsgroups org.open-mesh.lists.batman
Message-ID <[email protected]>
The unix socket path needs to be stored in sockaddr_un::sun_path. But
strncpy() is silently truncating the string when the target buffer is too
small.

Reject such paths with a clear error message.

Fixes: 6c6a6f735054 ("alfred: Make unix socket path configurable")
Signed-off-by: Sven Eckelmann <[email protected]>
---
 vis/vis.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/vis/vis.c b/vis/vis.c
index 4642227..d635798 100644
--- a/vis/vis.c
+++ b/vis/vis.c
@@ -152,6 +152,12 @@ static int alfred_open_sock(struct globals *globals)
 {
 	struct sockaddr_un addr;
 
+	if (strlen(globals->unix_path) >= sizeof(addr.sun_path)) {
+		fprintf(stderr, "unix socket path too long\n");
+		globals->unix_sock = -1;
+		return -1;
+	}
+
 	globals->unix_sock = socket(AF_LOCAL, SOCK_STREAM, 0);
 	if (globals->unix_sock < 0) {
 		perror("can't create unix socket");

-- 
2.47.3