Skip to content

Reader reads free memory #5

Open
@geigerzaehler

Description

@geigerzaehler

It is possible for the reader to read freed memory.

The following example will panic at the assertion. The reader will read from the memory location previously occupied by write_buf which is now occupied by read_buf.

let (mut writer, mut reader) = pipe();
let mut write_buf = vec![0u8; 1024];
let _ = futures::poll!(writer.write_all(&mut write_buf));
drop(write_buf);

// Fill the space previously used by `write_buf`
let write_buf_overwrite = vec![1u8; 1024];
let mut read_buf = vec![0u8; 1024];
reader.read_exact(&mut read_buf).await.unwrap();
assert_eq!(read_buf, vec![0u8; 1024]);
drop(write_buf_overwrite);

To address this I’d suggest to copy the the write buffer into state.data instead of using *const u8.

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