LibCore: Fix struct msghdr initialization

The previous approach could leave behind uninitialized fields on
platforms which have additional fields in this structure (e.g. padding
fields on musl libc).
This commit is contained in:
Drew DeVault 2022-12-13 11:32:17 +01:00 committed by Brian Gianforcaro
parent a06b277471
commit c7f8d74c1c
Notes: sideshowbarker 2024-07-17 09:47:09 +09:00

View file

@ -605,15 +605,11 @@ ErrorOr<int> LocalSocket::receive_fd(int flags)
.iov_base = &c, .iov_base = &c,
.iov_len = 1, .iov_len = 1,
}; };
struct msghdr msg { struct msghdr msg = {};
.msg_name = NULL, msg.msg_iov = &iov;
.msg_namelen = 0, msg.msg_iovlen = 1;
.msg_iov = &iov, msg.msg_control = cmsgu.control;
.msg_iovlen = 1, msg.msg_controllen = sizeof(cmsgu.control);
.msg_control = cmsgu.control,
.msg_controllen = sizeof(cmsgu.control),
.msg_flags = 0,
};
TRY(Core::System::recvmsg(m_helper.fd(), &msg, 0)); TRY(Core::System::recvmsg(m_helper.fd(), &msg, 0));
struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
@ -652,15 +648,11 @@ ErrorOr<void> LocalSocket::send_fd(int fd)
char control[CMSG_SPACE(sizeof(int))]; char control[CMSG_SPACE(sizeof(int))];
} cmsgu {}; } cmsgu {};
struct msghdr msg { struct msghdr msg = {};
.msg_name = NULL, msg.msg_iov = &iov;
.msg_namelen = 0, msg.msg_iovlen = 1;
.msg_iov = &iov, msg.msg_control = cmsgu.control;
.msg_iovlen = 1, msg.msg_controllen = sizeof(cmsgu.control);
.msg_control = cmsgu.control,
.msg_controllen = sizeof(cmsgu.control),
.msg_flags = 0,
};
struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_len = CMSG_LEN(sizeof(int)); cmsg->cmsg_len = CMSG_LEN(sizeof(int));