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

Misaligned pointer dereference in sa_in and sa_in6 #30

Open
shinmao opened this issue Sep 21, 2023 · 0 comments
Open

Misaligned pointer dereference in sa_in and sa_in6 #30

shinmao opened this issue Sep 21, 2023 · 0 comments

Comments

@shinmao
Copy link

shinmao commented Sep 21, 2023

The source of unsoundness

Hi, we found that two safe functions created misaligned pointers and dereference:

if-addrs/src/sockaddr.rs

Lines 99 to 108 in 947c634

#[allow(unsafe_code)]
#[allow(clippy::cast_ptr_alignment)]
fn sa_in(&self) -> sockaddr_in {
unsafe { *(self.inner.as_ptr() as *const sockaddr_in) }
}
#[allow(unsafe_code)]
#[allow(clippy::cast_ptr_alignment)]
fn sa_in6(&self) -> sockaddr_in6 {
unsafe { *(self.inner.as_ptr() as *const sockaddr_in6) }

At line 102 and 108, they both cast the type aligned to 2 bytes to the type aligned to 4 bytes. This could lead to undefined behavior in safe functions.

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

No branches or pull requests

1 participant