Skip to content

Commit

Permalink
utils: Ensure that the buffer for struct cmsghdr is suitably-aligned
Browse files Browse the repository at this point in the history
A char array on the stack is not guaranteed to have any particular
alignment.

Resolves: containers#637
Signed-off-by: Simon McVittie <[email protected]>
  • Loading branch information
smcv committed Oct 17, 2024
1 parent 3392345 commit 1fd7c38
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ send_pid_on_socket (int sockfd)
struct msghdr msg = {};
struct iovec iov = { buf, sizeof (buf) };
const ssize_t control_len_snd = CMSG_SPACE(sizeof(struct ucred));
char control_buf_snd[control_len_snd];
_Alignas(struct cmsghdr) char control_buf_snd[control_len_snd];
struct cmsghdr *cmsg;
struct ucred cred;

Expand Down Expand Up @@ -801,7 +801,7 @@ read_pid_from_socket (int sockfd)
struct msghdr msg = {};
struct iovec iov = { recv_buf, sizeof (recv_buf) };
const ssize_t control_len_rcv = CMSG_SPACE(sizeof(struct ucred));
char control_buf_rcv[control_len_rcv];
_Alignas(struct cmsghdr) char control_buf_rcv[control_len_rcv];
struct cmsghdr* cmsg;

msg.msg_iov = &iov;
Expand Down

0 comments on commit 1fd7c38

Please sign in to comment.