summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-10-15 19:24:04 +0000
committerGitHub <noreply@github.com>2019-10-15 19:24:04 +0000
commit5d76d33690431c36e2bd664623015294d1a6b6d1 (patch)
tree66d6eb4bd36d5b5da61ade54d6fdf7831cf0a38d
parenta220ded341b826275b4243722af417f55cb23be0 (diff)
parenta510b47aa073318df23531f48fd6ae3083baf703 (diff)
downloadnix-5d76d33690431c36e2bd664623015294d1a6b6d1.zip
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 <yshuiv7@gmail.com>
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/sys/socket/mod.rs4
2 files changed, 4 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e719987d..fa18a429 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -54,6 +54,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- Fix length of abstract socket addresses
([#1120](https://github.com/nix-rust/nix/pull/1120))
+- Fix initialization of msghdr in recvmsg/sendmsg when built with musl
+ ([#1136](https://github.com/nix-rust/nix/pull/1136))
### Removed
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index ca4505fa..9e8cefae 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -857,7 +857,7 @@ pub fn sendmsg(fd: RawFd, iov: &[IoVec<&[u8]>], cmsgs: &[ControlMessage],
let mhdr = unsafe {
// Musl's msghdr has private fields, so this is the only way to
// initialize it.
- let mut mhdr = mem::MaybeUninit::<msghdr>::uninit();
+ let mut mhdr = mem::MaybeUninit::<msghdr>::zeroed();
let p = mhdr.as_mut_ptr();
(*p).msg_name = name as *mut _;
(*p).msg_namelen = namelen;
@@ -910,7 +910,7 @@ pub fn recvmsg<'a>(fd: RawFd, iov: &[IoVec<&mut [u8]>],
let mut mhdr = unsafe {
// Musl's msghdr has private fields, so this is the only way to
// initialize it.
- let mut mhdr = mem::MaybeUninit::<msghdr>::uninit();
+ let mut mhdr = mem::MaybeUninit::<msghdr>::zeroed();
let p = mhdr.as_mut_ptr();
(*p).msg_name = address.as_mut_ptr() as *mut c_void;
(*p).msg_namelen = mem::size_of::<sockaddr_storage>() as socklen_t;