valpackett / systemstat

Rust library for getting system information | also on https://codeberg.org/valpackett/systemstat
https://crates.io/crates/systemstat
The Unlicense
610 stars 71 forks source link

misaligned pointer dereference in `platform::unix::parse_addr` #125

Closed shinmao closed 2 months ago

shinmao commented 2 months ago

Unsoundness

Hi, as I saw "this is horrible" in your code of parse_addr, does it mean the misaligned raw pointer addr6 created in line 54 could cause to undefined behavior here? https://github.com/valpackett/systemstat/blob/cbd9c1638b792d1819479f0c2baa5840f65af727/src/platform/unix.rs#L52-L57 As I know, misaligned pointer dereference here might have inconsistent value in different architecture, so we should avoid it.

valpackett commented 2 months ago

"This is horrible" refers to the whole sequence, with three unsafe expressions close together (:

How could addr6 be misaligned? It is a *const sockaddr we get from the OS, which is meant to be reinterpreted as sockaddr_<depending on sa_family>; we don't do anything weird with it.

…also you've already reported this: #120