| 1 | diff --git a/src/pulsecore/iochannel.c b/src/pulsecore/iochannel.c |
| 2 | index 8ace297ff..897337522 100644 |
| 3 | --- a/src/pulsecore/iochannel.c |
| 4 | +++ b/src/pulsecore/iochannel.c |
| 5 | @@ -355,7 +355,7 @@ ssize_t pa_iochannel_write_with_fds(pa_iochannel*io, const void*data, size_t l, |
| 6 | struct iovec iov; |
| 7 | union { |
| 8 | struct cmsghdr hdr; |
| 9 | - uint8_t data[CMSG_SPACE(sizeof(int) * nfd)]; |
| 10 | + uint8_t data[CMSG_SPACE(sizeof(int) * MAX_ANCIL_DATA_FDS)]; |
| 11 | } cmsg; |
| 12 | |
| 13 | pa_assert(io); |
| 14 | @@ -382,7 +382,13 @@ ssize_t pa_iochannel_write_with_fds(pa_iochannel*io, const void*data, size_t l, |
| 15 | mh.msg_iov = &iov; |
| 16 | mh.msg_iovlen = 1; |
| 17 | mh.msg_control = &cmsg; |
| 18 | - mh.msg_controllen = sizeof(cmsg); |
| 19 | + |
| 20 | + /* If we followed the example on the cmsg man page, we'd use |
| 21 | + * sizeof(cmsg.data) here, but if nfd < MAX_ANCIL_DATA_FDS, then the data |
| 22 | + * buffer is larger than needed, and the kernel doesn't like it if we set |
| 23 | + * msg_controllen to a larger than necessary value. The commit message for |
| 24 | + * commit 451d1d6762 contains a longer explanation. */ |
| 25 | + mh.msg_controllen = CMSG_SPACE(sizeof(int) * nfd); |
| 26 | |
| 27 | if ((r = sendmsg(io->ofd, &mh, MSG_NOSIGNAL)) >= 0) { |
| 28 | io->writable = io->hungup = false; |