You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
We found 2 cases (below) where a double drop of an objects can happen
if a panic occurs within the user-provided Into<Event> implementation.
letmut el = EventList::with_capacity(events.len());
for idx in 0..events.len(){
let event = unsafe{ ptr::read(events.get_unchecked(idx))};
el.push(event.into());
}
// Ownership has been unsafely transfered to the new event
// list without modifying the event reference count. Not
// forgetting the source array would cause a double drop.
mem::forget(events);
el
}
}
Proof of Concept
The example program below exhibits a double-drop.
use fil_ocl::{Event,EventList};use std::convert::Into;structFoo(Option<i32>);implInto<Event>forFoo{fninto(self) -> Event{/* According to the docs, `Into<T>` implementations shouldn't panic. However rustc doesn't check whether panics can happen in the Into implementation, so it's possible for a user-provided `into()` to panic.. */println!("LOUSY PANIC : {}", self.0.unwrap());Event::empty()}}implDropforFoo{fndrop(&mutself){println!("I'm dropping");}}fnmain(){let eventlist:EventList = [Foo(None)].into();dbg!(eventlist);}
Suggested Fix
In this case, using ManuallyDrop can help guard against the potential panic within into().
I'll submit a PR with the suggested fix right away.
Thank you for checking out this issue 👍
The text was updated successfully, but these errors were encountered:
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
We found 2 cases (below) where a double drop of an objects can happen
if a panic occurs within the user-provided
Into<Event>
implementation.ocl/ocl/src/standard/event.rs
Lines 1000 to 1014 in 0308686
ocl/ocl/src/standard/event.rs
Lines 1037 to 1050 in 0308686
Proof of Concept
The example program below exhibits a double-drop.
Suggested Fix
In this case, using
ManuallyDrop
can help guard against the potential panic withininto()
.I'll submit a PR with the suggested fix right away.
Thank you for checking out this issue 👍
The text was updated successfully, but these errors were encountered: