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.
This commit is contained in:
Lennart Poettering
2020-05-07 14:39:44 +02:00
parent 0d9d333672
commit fb29cdbef2
22 changed files with 66 additions and 121 deletions
+1 -5
View File
@@ -859,13 +859,10 @@ int ask_password_agent(
pollfd[FD_INOTIFY].events = POLLIN;
for (;;) {
CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(struct ucred))) control;
char passphrase[LINE_MAX+1];
struct iovec iovec;
struct ucred *ucred;
union {
struct cmsghdr cmsghdr;
uint8_t buf[CMSG_SPACE(sizeof(struct ucred))];
} control;
ssize_t n;
int k;
usec_t t;
@@ -917,7 +914,6 @@ int ask_password_agent(
iovec = IOVEC_MAKE(passphrase, sizeof(passphrase));
zero(control);
struct msghdr msghdr = {
.msg_iov = &iovec,
.msg_iovlen = 1,