[PATCH 5/6] alfred: reject too long unix socket paths
Sven Eckelmann <[email protected]> Thu, 30 Jul 2026 21:31:59 +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. Signed-off-by: Sven Eckelmann <[email protected]> --- unix_sock.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/unix_sock.c b/unix_sock.c index e6b44da..99c2538 100644 --- a/unix_sock.c +++ b/unix_sock.c @@ -35,6 +35,11 @@ int unix_sock_open_daemon(struct globals *globals) struct sockaddr_un addr; struct epoll_event ev; + if (strlen(globals->unix_path) >= sizeof(addr.sun_path)) { + fprintf(stderr, "unix socket path too long\n"); + return -1; + } + unlink(globals->unix_path); globals->unix_sock = socket(AF_LOCAL, SOCK_STREAM, 0); @@ -76,6 +81,11 @@ int unix_sock_open_client(struct globals *globals) { struct sockaddr_un addr; + if (strlen(globals->unix_path) >= sizeof(addr.sun_path)) { + fprintf(stderr, "unix socket path too long\n"); + 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