diff options
author | Drew DeVault <sir@cmpwn.com> | 2022-12-13 11:32:17 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-12-13 10:12:59 -0800 |
commit | c7f8d74c1c5ab96103891d7956772cdc90b3bec3 (patch) | |
tree | c9b33d8d28774956d6635ecc1899f15ff853f2ed /Userland/Libraries/LibCore | |
parent | a06b2774712922a2c2a149b92864689be9ed24f8 (diff) | |
download | serenity-c7f8d74c1c5ab96103891d7956772cdc90b3bec3.zip |
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).
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r-- | Userland/Libraries/LibCore/Stream.cpp | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/Userland/Libraries/LibCore/Stream.cpp b/Userland/Libraries/LibCore/Stream.cpp index bae56c00c5..9b00aaed8f 100644 --- a/Userland/Libraries/LibCore/Stream.cpp +++ b/Userland/Libraries/LibCore/Stream.cpp @@ -605,15 +605,11 @@ ErrorOr<int> LocalSocket::receive_fd(int flags) .iov_base = &c, .iov_len = 1, }; - struct msghdr msg { - .msg_name = NULL, - .msg_namelen = 0, - .msg_iov = &iov, - .msg_iovlen = 1, - .msg_control = cmsgu.control, - .msg_controllen = sizeof(cmsgu.control), - .msg_flags = 0, - }; + struct msghdr msg = {}; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = cmsgu.control; + msg.msg_controllen = sizeof(cmsgu.control); TRY(Core::System::recvmsg(m_helper.fd(), &msg, 0)); struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); @@ -652,15 +648,11 @@ ErrorOr<void> LocalSocket::send_fd(int fd) char control[CMSG_SPACE(sizeof(int))]; } cmsgu {}; - struct msghdr msg { - .msg_name = NULL, - .msg_namelen = 0, - .msg_iov = &iov, - .msg_iovlen = 1, - .msg_control = cmsgu.control, - .msg_controllen = sizeof(cmsgu.control), - .msg_flags = 0, - }; + struct msghdr msg = {}; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = cmsgu.control; + msg.msg_controllen = sizeof(cmsgu.control); struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_len = CMSG_LEN(sizeof(int)); |