Skip to content

Commit 5d76d33

Browse files
bors[bot]yshui
andauthored
Merge #1136
1136: Properly initialize msghdr when using musl r=posborne a=yshui Because of the use of MaybeUninit::uninit, the padding fields in msghdr, which only present on musl builds, are not initialized. Causing garbage data to be sent to the kernel. This change ensures the paddings are always zeroed. Co-authored-by: Yuxuan Shui <[email protected]>
2 parents a220ded + a510b47 commit 5d76d33

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5454
### Fixed
5555
- Fix length of abstract socket addresses
5656
([#1120](https://github.com/nix-rust/nix/pull/1120))
57+
- Fix initialization of msghdr in recvmsg/sendmsg when built with musl
58+
([#1136](https://github.com/nix-rust/nix/pull/1136))
5759

5860
### Removed
5961

src/sys/socket/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ pub fn sendmsg(fd: RawFd, iov: &[IoVec<&[u8]>], cmsgs: &[ControlMessage],
857857
let mhdr = unsafe {
858858
// Musl's msghdr has private fields, so this is the only way to
859859
// initialize it.
860-
let mut mhdr = mem::MaybeUninit::<msghdr>::uninit();
860+
let mut mhdr = mem::MaybeUninit::<msghdr>::zeroed();
861861
let p = mhdr.as_mut_ptr();
862862
(*p).msg_name = name as *mut _;
863863
(*p).msg_namelen = namelen;
@@ -910,7 +910,7 @@ pub fn recvmsg<'a>(fd: RawFd, iov: &[IoVec<&mut [u8]>],
910910
let mut mhdr = unsafe {
911911
// Musl's msghdr has private fields, so this is the only way to
912912
// initialize it.
913-
let mut mhdr = mem::MaybeUninit::<msghdr>::uninit();
913+
let mut mhdr = mem::MaybeUninit::<msghdr>::zeroed();
914914
let p = mhdr.as_mut_ptr();
915915
(*p).msg_name = address.as_mut_ptr() as *mut c_void;
916916
(*p).msg_namelen = mem::size_of::<sockaddr_storage>() as socklen_t;

0 commit comments

Comments
 (0)