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

Changes in memory layout of the std net types will result in UB #9

Closed
ghost opened this issue Sep 10, 2022 · 2 comments · Fixed by #10
Closed

Changes in memory layout of the std net types will result in UB #9

ghost opened this issue Sep 10, 2022 · 2 comments · Fixed by #10

Comments

@ghost
Copy link

ghost commented Sep 10, 2022

Context: rust-lang/rust#78802 and https://www.reddit.com/r/rust/comments/wcw93o/a_major_refactor_of_rusts_ip_address/

These lines caught my eye while I was reading the code:

netif/src/lib.rs

Lines 189 to 190 in 550ec42

// Leans on the fact that SocketAddrV4 and SocketAddrV6 are
// transparent wrappers around SOCKADDR.

netif/src/lib.rs

Lines 331 to 332 in 550ec42

// Leans on the fact that SocketAddrV4 and SocketAddrV6 are
// transparent wrappers around sockaddr_in and sockaddr_in6.

A lot of crates were recently patched to remove the assumption of the memory layout of network primitives. Any code continuing to do so will result in UB, so I wanted to raise this issue.

@bnoordhuis
Copy link
Owner

It should be fairly easy to fix. Do you want to send a PR or should I?

@ghost
Copy link
Author

ghost commented Sep 10, 2022

I never used libc/winapi or unsafe stuff, so I probably wouldn't know what to do. I'll leave it to you =)

bnoordhuis added a commit that referenced this issue Sep 12, 2022
std::net::Ipv4Addr and std::net::Ipv6Addr are no longer transparent
wrappers around their respective libc types. Construct them manually
rather than through casting.

Fixes #9.
bnoordhuis added a commit that referenced this issue Sep 12, 2022
std::net::Ipv4Addr and std::net::Ipv6Addr are no longer transparent
wrappers around their respective libc types. Construct them manually
rather than through casting.

Fixes #9.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant