messense / if-addrs

Retrieve IP addresses for all interfaces. POSIX & Windows
BSD 3-Clause "New" or "Revised" License
22 stars 15 forks source link

Misaligned pointer dereference in `sa_in` and `sa_in6` #30

Open shinmao opened 10 months ago

shinmao commented 10 months ago

The source of unsoundness

Hi, we found that two safe functions created misaligned pointers and dereference: https://github.com/messense/if-addrs/blob/947c6342681b047b48b5f53eb75049881d2dfa20/src/sockaddr.rs#L99-L108 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.