Open shinmao opened 1 year ago
[UPDATED]
There is another unsound implementation in convert
:
https://github.com/Koka/odbc-rs/blob/f9e5f77fac0a6328f9759e6e0f9e10c16509aebb/src/statement/types.rs#L139-L142
which also create a misaligned pointer and passed to from_raw_parts
.
The source of unsoundness
Hi, we are the researchers from Sun Security Lab. With our bug detector, we found that
convert_primitive
might have an unsound implementation. https://github.com/Koka/odbc-rs/blob/f9e5f77fac0a6328f9759e6e0f9e10c16509aebb/src/statement/types.rs#L281-L286 At line 285,buf
is aligned to 1 byte, and it can be cast to other types with stricter alignment requirement. If misaligned pointer is passed tofrom_raw_parts
, it could cause to undefined behavior in this safe function.To reproduce the bug
In this case,
convert
will callfrom_raw_parts(x.as_ptr() as *const u32, 1)
which has a misaligned pointer.run with miri
In this case, the length of the buffer is only 2 bytes. However,
from_raw_parts
expects 8 bytes to be read.