-
Notifications
You must be signed in to change notification settings - Fork 528
Description
Line 165 in e8b13ba
.read(unsafe { &mut *(buffer.spare_capacity_mut() as *mut _ as *mut [u8]) }) |
Our unsafe review found that this line constructs a reference that could expose uninitialized memory. The read
API requires that initialized (e.g. zeroed) memory be used.
The docs for read
say:
"... it is possible that the code that’s supposed to write to the buffer might also read from it. It is your responsibility to make sure that buf is initialized before calling read. Calling read with an uninitialized buf (of the kind one obtains via MaybeUninit) is not safe, and can lead to undefined behavior."
Now, the safety comment does says that we assume stderr never reads.
Yet, the contract for the read
method provides no such guarantee.
Would it make sense to initialize?
Or provide better justification why stderr.read will never ever read the buffer?