Closed shinmao closed 10 months ago
I meant that usage of transmute
was required in general :)
There is no other way to implement this conversion (directly, not considering going through string representations which would be slow); there is no actual safety problem here.
This parsing is only ever done on data returned from libc, so we know that addr.sa_family == AF_INET6
guarantees that the *const sockaddr
was actually a cast from *const sockaddr_in6
. There's no compile time guarantee because, well, stupid unix history reasons.
Hi, we are the researchers from SunLab, we found that
parse_addr
might have unsound implementation with our bug detector. https://github.com/valpackett/systemstat/blob/cbd9c1638b792d1819479f0c2baa5840f65af727/src/platform/unix.rs#L53-L55aptr
is aligned to 2 bytes whilesockaddr_in6
is aligned to 4 bytes. Type conversion withtransmute
could create a misaligned pointer. In following line, the misaligned pointer dereference happens with*addr6
.Maybe that's also what you mean by
horrible
? (: