Skip to content

Unsoundness in command_helpers.rs #1200

@burakemir

Description

@burakemir

.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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions