Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add non-NULL asserts to CMSG_* returns, null-initialize AncillaryBuf #8

Merged
merged 1 commit into from
Aug 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/ancillary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,19 @@ pub fn send_ancillary(
}

#[cfg(not(any(target_os="illumos", target_os="solaris")))] {
let mut header = &mut*CMSG_FIRSTHDR(&mut msg);
let header_ptr = CMSG_FIRSTHDR(&mut msg);
assert!(!header_ptr.is_null(), "CMSG_FIRSTHDR returned unexpected NULL pointer");
#[allow(unused_mut)]
let mut header = &mut*header_ptr;
#[cfg(any(target_os="linux", target_os="android"))] {
if let Some(creds) = creds {
header.cmsg_level = SOL_SOCKET;
header.cmsg_type = SCM_CREDENTIALS;
header.cmsg_len = CMSG_LEN(mem::size_of_val(&creds) as u32) as ControlLen;
*(CMSG_DATA(header) as *mut c_void as *mut _) = creds;
header = &mut*CMSG_NXTHDR(&mut msg, header);
domenukk marked this conversation as resolved.
Show resolved Hide resolved
let header_ptr = CMSG_NXTHDR(&mut msg, header);
assert!(!header_ptr.is_null(), "CMSG_NXTHDR returned unexpected NULL pointer");
header = &mut*header_ptr;
}
}

Expand Down Expand Up @@ -194,7 +199,7 @@ impl AncillaryBuf {
bytes as usize,
mem::align_of::<cmsghdr>()
).unwrap();
alloc::alloc(layout)
alloc::alloc_zeroed(layout)
},
_ => panic!("capacity is too high"),
},
Expand Down