summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-09-09 14:44:52 +0200
committerLennart Poettering <lennart@poettering.net>2015-09-09 14:44:52 +0200
commit5bdb84b393157bfd49e33450d883804383684923 (patch)
tree695bf2fe47d648fe91d30d88400e4e9cd5f38b87
parent0f9415d44c9951f3479a05cb07e41d3c70bf95f2 (diff)
parenta5bd3c32abb00ad945282568fd1a97c180b68047 (diff)
Merge pull request #1215 from maciejaszek/fds_pass_fixes
sd_pid_notify_with_fds: fix computing msg_controllen
-rw-r--r--src/libsystemd/sd-daemon/sd-daemon.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c
index d230a48daf..9ec73406c6 100644
--- a/src/libsystemd/sd-daemon/sd-daemon.c
+++ b/src/libsystemd/sd-daemon/sd-daemon.c
@@ -395,8 +395,9 @@ _public_ int sd_pid_notify_with_fds(pid_t pid, int unset_environment, const char
have_pid = pid != 0 && pid != getpid();
if (n_fds > 0 || have_pid) {
- msghdr.msg_controllen = CMSG_SPACE(sizeof(int) * n_fds) +
- CMSG_SPACE(sizeof(struct ucred) * have_pid);
+ /* CMSG_SPACE(0) may return value different then zero, which results in miscalculated controllen. */
+ msghdr.msg_controllen = (n_fds ? CMSG_SPACE(sizeof(int) * n_fds) : 0) +
+ CMSG_SPACE(sizeof(struct ucred)) * have_pid;
msghdr.msg_control = alloca(msghdr.msg_controllen);
cmsg = CMSG_FIRSTHDR(&msghdr);