This repository was archived by the owner on May 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
This repository was archived by the owner on May 1, 2021. It is now read-only.
Invalid assumption of SocketAddrV{4,6} layout #1
Copy link
Copy link
Closed
Description
This code assumes that Rust's std::net::{SocketAddrV4, SocketAddrV6} are layout compatible with sockaddr:
Lines 61 to 84 in f706c11
| impl Addr { | |
| /// Creates a raw socket address from `SocketAddr`. | |
| fn new(addr: SocketAddr) -> Self { | |
| let (addr, len): (*const sockaddr, socklen_t) = match &addr { | |
| SocketAddr::V4(addr) => (addr as *const _ as *const _, mem::size_of_val(addr) as _), | |
| SocketAddr::V6(addr) => (addr as *const _ as *const _, mem::size_of_val(addr) as _), | |
| }; | |
| unsafe { Self::from_raw_parts(addr, len) } | |
| } | |
| /// Creates an `Addr` from its raw parts. | |
| unsafe fn from_raw_parts(addr: *const sockaddr, len: socklen_t) -> Self { | |
| let mut storage = MaybeUninit::<sockaddr_storage>::uninit(); | |
| ptr::copy_nonoverlapping( | |
| addr as *const _ as *const u8, | |
| &mut storage as *mut _ as *mut u8, | |
| len as usize, | |
| ); | |
| Self { | |
| storage: storage.assume_init(), | |
| len, | |
| } | |
| } | |
| } |
This is not guaranteed by the standard library, see rust-lang/rust#78802 for more details.
Metadata
Metadata
Assignees
Labels
No labels