From 1d261418e280a7918549d638d574fbea08cf79a9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 15 Oct 2018 18:17:57 +0200 Subject: [PATCH] sd-bus: make parsing of AF_UNIX socket addresses more strict Insist on NUL termination, just to be safe rather than sorry. The kernel doesn't require it, but it's really annoying if people rely on this, hence refuse this early. --- src/libsystemd/sd-bus/sd-bus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 7868e53..d6c0095 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -730,7 +730,7 @@ static int parse_unix_address(sd_bus *b, const char **p, char **guid) { if (path) { l = strlen(path); - if (l > sizeof(b->sockaddr.un.sun_path)) + if (l >= sizeof(b->sockaddr.un.sun_path)) /* We insist on NUL termination */ return -E2BIG; b->sockaddr.un.sun_family = AF_UNIX; @@ -738,7 +738,7 @@ static int parse_unix_address(sd_bus *b, const char **p, char **guid) { b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + l; } else if (abstract) { l = strlen(abstract); - if (l > sizeof(b->sockaddr.un.sun_path) - 1) + if (l >= sizeof(b->sockaddr.un.sun_path) - 1) /* We insist on NUL termination */ return -E2BIG; b->sockaddr.un.sun_family = AF_UNIX; -- 2.7.4