Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventList::From for Into<Event> slices can cause double-drop #198

Closed
ammaraskar opened this issue Feb 3, 2021 · 1 comment
Closed

EventList::From for Into<Event> slices can cause double-drop #198

ammaraskar opened this issue Feb 3, 2021 · 1 comment

Comments

@ammaraskar
Copy link

Hi there, we (Rust group @sslab-gatech) are scanning crates on crates.io for potential soundness bugs. We noticed that in the EventList::From implementation for slices of types that implement Into<Event>:

ocl/ocl/src/standard/event.rs

Lines 1040 to 1043 in 0308686

for idx in 0..events.len() {
let event = unsafe { ptr::read(events.get_unchecked(idx)) };
el.push(event.into());
}

It grabs the event using ptr::read duplicating the ownership and then calls event.into() which can potentially panic. This can lead to the event being double freed as shown in the example below:

#![forbid(unsafe_code)]

use ocl::{Event, EventList};

struct MyIntoEventType(u32);

impl Drop for MyIntoEventType {
    fn drop(&mut self) {
        println!("Dropping the MyIntoEventType");
    }
}

impl Into<Event> for MyIntoEventType {
    fn into(self) -> Event {
        panic!("Panicking in Into");
    }
}

fn main() {
    let slice = [MyIntoEventType(1)];
    let event_list = EventList::from(slice);
}

Output:

thread 'main' panicked at 'Panicking in Into', src/main.rs:28:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Dropping the MyIntoEventType
Dropping the MyIntoEventType
@ammaraskar
Copy link
Author

Aah this was already reported as part of #194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant