Skip to content

Misaligned pointer dereference in sa_in and sa_in6 #30

@shinmao

Description

@shinmao

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions