[PATCH 2/4] main: strip trailing null bytes from systemd notify socket path
Martin Hundebøll <[email protected]> Fri, 10 Oct 2025 11:20:03 +0200
| Newsgroups | dev.linux.lists.ell |
|---|---|
| Message-ID | <[email protected]> |
When connecting to abstract unix sockets, the trailing null bytes are
considered as part of the (abstract) socket path, hence failing the
connection if the abstract name doesn't fill up the socket pacth member.
Fix support for abstract notify socket names by only passing the
absolutely needed size of the socket address structure when connecting
(i.e. the two family bytes, the null path prefix, and the path name).
---
ell/main.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/ell/main.c b/ell/main.c
index 5e391b7e62b3..be9d96377f07 100644
--- a/ell/main.c
+++ b/ell/main.c
@@ -350,6 +350,7 @@ static void create_sd_notify_socket(void)
const char *sock;
struct sockaddr_un addr;
const char *watchdog_usec;
+ socklen_t len;
int msec;
/* check if NOTIFY_SOCKET has been set */
@@ -370,11 +371,12 @@ static void create_sd_notify_socket(void)
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, sock, sizeof(addr.sun_path) - 1);
+ len = offsetof(struct sockaddr_un, sun_path) + strlen(sock);
if (addr.sun_path[0] == '@')
addr.sun_path[0] = '\0';
- if (connect(notify_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+ if (connect(notify_fd, (struct sockaddr *) &addr, len) < 0) {
close(notify_fd);
notify_fd = 0;
return;
--
2.51.0