From fb29cdbef21f1d66e2ebe600601897b6578d3959 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 24 Apr 2020 23:54:25 +0200 Subject: tree-wide: make sure our control buffers are properly aligned We always need to make them unions with a "struct cmsghdr" in them, so that things properly aligned. Otherwise we might end up at an unaligned address and the counting goes all wrong, possibly making the kernel refuse our buffers. Also, let's make sure we initialize the control buffers to zero when sending, but leave them uninitialized when reading. Both the alignment and the initialization thing is mentioned in the cmsg(3) man page. --- src/journal/journald-stream.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/journal/journald-stream.c') diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 202ac3cda2..4dadbd62be 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -489,7 +489,7 @@ static int stdout_stream_scan(StdoutStream *s, bool force_flush) { } static int stdout_stream_process(sd_event_source *es, int fd, uint32_t revents, void *userdata) { - uint8_t buf[CMSG_SPACE(sizeof(struct ucred))]; + CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(struct ucred))) control; StdoutStream *s = userdata; struct ucred *ucred; struct iovec iovec; @@ -500,8 +500,8 @@ static int stdout_stream_process(sd_event_source *es, int fd, uint32_t revents, struct msghdr msghdr = { .msg_iov = &iovec, .msg_iovlen = 1, - .msg_control = buf, - .msg_controllen = sizeof(buf), + .msg_control = &control, + .msg_controllen = sizeof(control), }; assert(s); -- cgit v1.2.3