sysctl-rs icon indicating copy to clipboard operation
sysctl-rs copied to clipboard

`value_oid_as` is unsound

Open Nugine opened this issue 3 years ago • 1 comments

Transmuting bytes to an arbitrary type can cause undefined behavior.

The safety requirements:

  1. T must be Sized.
  2. The length of bytes must be equal to size_of::<T>().
  3. The alignment of bytes must be equal to align_of::<T>().
  4. T must be valid for any binary representation.

https://github.com/johalun/sysctl-rs/blob/57c05e11519b26caed6ccc9260a3b84e185f80d1/src/unix/funcs.rs#L367-L369

Nugine avatar Jul 14 '21 15:07 Nugine

+1

bigdogs avatar Apr 12 '22 08:04 bigdogs