diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index dd74013c64..c7c2bbb5ab 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -2059,7 +2059,10 @@ unsafe fn pack_mhdr_to_receive( let mut mhdr = mem::MaybeUninit::::zeroed(); let p = mhdr.as_mut_ptr(); unsafe { - (*p).msg_name = address as *mut c_void; + // it is important to use as_mut_ptr() here since S can be + // a zero sized type representing by a dangling pointer. + // as_mut_ptr() handles this case and uses a null pointer instead + (*p).msg_name = (*address).as_mut_ptr(); (*p).msg_namelen = S::size(); (*p).msg_iov = iov_buffer as *mut iovec; (*p).msg_iovlen = iov_buffer_len as _;