Skip to content

uninitialized memory can be dropped on panic: 'misc::vec_with_size()' #45

Closed
@JOE1994

Description

@JOE1994

Hello,
we (Rust group @sslab-gatech) found a memory-safety/soundness issue in this crate while scanning Rust code on crates.io for potential vulnerabilities.

Issue Description

telemetry.rs/src/misc.rs

Lines 138 to 151 in 5c810a8

pub fn vec_with_size<T>(size: usize, value: T) -> Vec<T>
where T: Clone
{
let mut vec = Vec::with_capacity(size);
unsafe {
// Resize. In future versions of Rust, we should
// be able to use `vec.resize`.
vec.set_len(size);
for i in 0 .. size {
vec[i] = value.clone();
}
}
vec
}

User provided T::clone() can potentially panic, and if T::clone() panics while vec is (partially) uninitialized, uninitialized memory (uninitialized T) is dropped and can lead to undefined behavior.

Thank you for checking out this issue :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions