diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-10-15 18:22:04 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-10-15 19:40:51 +0200 |
commit | 95cb14b0681692d372e7b0bfb3c9a9bbc6ffbd0d (patch) | |
tree | 62560dd15c56695be03aa3e3f9d53a3a7c875e4f /src/libsystemd/sd-bus/sd-bus.c | |
parent | sd-bus: make parsing of AF_UNIX socket addresses more strict (diff) | |
download | systemd-95cb14b0681692d372e7b0bfb3c9a9bbc6ffbd0d.tar.xz systemd-95cb14b0681692d372e7b0bfb3c9a9bbc6ffbd0d.zip |
sd-bus: rework how we initialize struct sockaddr_un
Let's use structured initialization, but more importantly, let's
increase salen by 1, if we reference AF_UNIX sockets in the file system,
so that they also contain the trailing NUL byte. This is what unix(7)
suggests to do, hence follow it.
Diffstat (limited to '')
-rw-r--r-- | src/libsystemd/sd-bus/sd-bus.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index d6c0095161..85558d9c05 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -733,17 +733,25 @@ static int parse_unix_address(sd_bus *b, const char **p, char **guid) { if (l >= sizeof(b->sockaddr.un.sun_path)) /* We insist on NUL termination */ return -E2BIG; - b->sockaddr.un.sun_family = AF_UNIX; - strncpy(b->sockaddr.un.sun_path, path, sizeof(b->sockaddr.un.sun_path)); - b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + l; - } else if (abstract) { + b->sockaddr.un = (struct sockaddr_un) { + .sun_family = AF_UNIX, + }; + + memcpy(b->sockaddr.un.sun_path, path, l); + b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + l + 1; + + } else { + assert(abstract); + l = strlen(abstract); if (l >= sizeof(b->sockaddr.un.sun_path) - 1) /* We insist on NUL termination */ return -E2BIG; - b->sockaddr.un.sun_family = AF_UNIX; - b->sockaddr.un.sun_path[0] = 0; - strncpy(b->sockaddr.un.sun_path+1, abstract, sizeof(b->sockaddr.un.sun_path)-1); + b->sockaddr.un = (struct sockaddr_un) { + .sun_family = AF_UNIX, + }; + + memcpy(b->sockaddr.un.sun_path+1, abstract, l); b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + 1 + l; } |