diff options
author | Maciej Wereski <m.wereski@partner.samsung.com> | 2015-09-08 15:36:30 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-03-29 10:45:09 +0200 |
commit | bfe9c16671c456eb4c12e0ec01564c43a73c3127 (patch) | |
tree | 8c080291d747315796964dbbbc9e35b8f745ba10 /src | |
parent | eeeefb47fde1f010e14c9f0a6104bba011ce9b20 (diff) |
sd_pid_notify_with_fds: fix computing msg_controllen
CMSG_SPACE(0) may return value other than 0. This caused sendmsg to fail
with EINVAL, when have_pid or n_fds was 0.
Diffstat (limited to 'src')
-rw-r--r-- | src/libelogind/sd-daemon/sd-daemon.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/libelogind/sd-daemon/sd-daemon.c b/src/libelogind/sd-daemon/sd-daemon.c index 7639b6d3b..f74f44c65 100644 --- a/src/libelogind/sd-daemon/sd-daemon.c +++ b/src/libelogind/sd-daemon/sd-daemon.c @@ -406,8 +406,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); |