summaryrefslogtreecommitdiff
path: root/src/libunixonacid/unixmessage_receive.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-04-23 00:00:10 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-04-23 00:00:10 +0000
commitb2eac2dedd62224df07148a9e42eae0197902c00 (patch)
tree7f78a7260c9b26f386da7cf177cc8a9034bade36 /src/libunixonacid/unixmessage_receive.c
parente48c16f37bac55820c605f82c07f04436a55f415 (diff)
downloadskalibs-b2eac2dedd62224df07148a9e42eae0197902c00.tar.xz
Align ancillary buffers on struct cmsghdr and int boundaries
Diffstat (limited to 'src/libunixonacid/unixmessage_receive.c')
-rw-r--r--src/libunixonacid/unixmessage_receive.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libunixonacid/unixmessage_receive.c b/src/libunixonacid/unixmessage_receive.c
index 9672b63..8ca8c0b 100644
--- a/src/libunixonacid/unixmessage_receive.c
+++ b/src/libunixonacid/unixmessage_receive.c
@@ -14,6 +14,12 @@
#include <skalibs/stralloc.h>
#include <skalibs/unixmessage.h>
+union aligner_u
+{
+ struct cmsghdr cmsghdr ;
+ int i ;
+} ;
+
static int const awesomeflags =
#ifdef SKALIBS_HASMSGDONTWAIT
MSG_DONTWAIT
@@ -36,7 +42,7 @@ static int const awesomeflags =
static int unixmessage_receiver_fill (unixmessage_receiver_t *b)
{
- char ancilbuf[CMSG_SPACE(b->auxb.a - 1)] ;
+ union aligner_u ancilbuf[1 + CMSG_SPACE(b->auxb.a - 1) / sizeof(union aligner_u)] ;
struct iovec iov[2] ;
struct msghdr msghdr =
{
@@ -46,7 +52,7 @@ static int unixmessage_receiver_fill (unixmessage_receiver_t *b)
.msg_iovlen = 2,
.msg_flags = 0,
.msg_control = b->fds_ok & 1 ? ancilbuf : 0,
- .msg_controllen = b->fds_ok & 1 ? sizeof(ancilbuf) : 0
+ .msg_controllen = b->fds_ok & 1 ? CMSG_SPACE(b->auxb.a - 1) : 0
} ;
ssize_t r = -1 ;
if (cbuffer_isfull(&b->mainb) || ((b->fds_ok & 1) && cbuffer_isfull(&b->auxb)))