Skip to content

Commit

Permalink
initialize msg_name with null pointer when msg_name is empty
Browse files Browse the repository at this point in the history
The msg_name field points to a caller-allocated buffer that is used to
return the source address if the socket is unconnected. The caller
should set msg_namelen to the size of this buffer before this call; upon
return from a successful call, msg_namelen will contain the length of
the returned address. If the application does not need to know the
source address, msg_name can be specified as NULL.

In case we use () msgname_len gets initialized with 0, but pointer to
the array with msg_name. This works for the first iteration somehow, but
after that kernel sets msgname_len to a non-zero and second invocation
with the same MultiHeader fails

Fixes #2506
  • Loading branch information
pacak committed Oct 30, 2024
1 parent 70f8fe0 commit aede26d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,7 @@ unsafe fn pack_mhdr_to_receive<S>(
let mut mhdr = mem::MaybeUninit::<msghdr>::zeroed();
let p = mhdr.as_mut_ptr();
unsafe {
(*p).msg_name = address as *mut c_void;
(*p).msg_name = if S::size() == 0 { ptr::null_mut() } else { (*address).as_mut_ptr() as *mut c_void };
(*p).msg_namelen = S::size();
(*p).msg_iov = iov_buffer as *mut iovec;
(*p).msg_iovlen = iov_buffer_len as _;
Expand Down

0 comments on commit aede26d

Please sign in to comment.