Skip to content

Commit aede26d

Browse files
committed
initialize msg_name with null pointer when msg_name is empty
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
1 parent 70f8fe0 commit aede26d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/sys/socket/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ unsafe fn pack_mhdr_to_receive<S>(
20022002
let mut mhdr = mem::MaybeUninit::<msghdr>::zeroed();
20032003
let p = mhdr.as_mut_ptr();
20042004
unsafe {
2005-
(*p).msg_name = address as *mut c_void;
2005+
(*p).msg_name = if S::size() == 0 { ptr::null_mut() } else { (*address).as_mut_ptr() as *mut c_void };
20062006
(*p).msg_namelen = S::size();
20072007
(*p).msg_iov = iov_buffer as *mut iovec;
20082008
(*p).msg_iovlen = iov_buffer_len as _;

0 commit comments

Comments
 (0)