Align buffer for cmsg

`char control[CMSG_SPACE(sizeof(*out_cmsg_value)) + 1];` is not aligned as
cmsghdr. Accessing its member may lead to a -fsanitize=alignment failure.
Align `control` to struct cmsghdr to fix the issue.

PiperOrigin-RevId: 555951052
This commit is contained in:
Fangrui Song
2023-08-11 07:51:59 -07:00
committed by gVisor bot
parent 31b8262ce0
commit 65bbd235a6
+1 -1
View File
@@ -258,7 +258,7 @@ void RecvCmsg(int sock, int cmsg_level, int cmsg_type, char buf[],
iov.iov_len = *buf_size,
};
// Add an extra byte to confirm we only read what we expected.
char control[CMSG_SPACE(sizeof(*out_cmsg_value)) + 1];
alignas(struct cmsghdr) char control[CMSG_SPACE(sizeof(*out_cmsg_value)) + 1];
msghdr msg = {
.msg_iov = &iov,
.msg_iovlen = 1,