johalun / sysctl-rs

A simplified Rust interface to the sysctl system call
MIT License
52 stars 23 forks source link

`value_oid_as` is unsound #33

Open Nugine opened 3 years ago

Nugine commented 3 years ago

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

bigdogs commented 2 years ago

+1