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
The signature of get_or_init_dependent improperly permits the caller to pick an arbitrarily short lifetime 'a, and then put a reference that is only live for 'a into Dependent. Then it's possible for them to later pick a longer lifetime 'b and get a Dependent<'b> back out, leading to Use After Free or other undefined behavior in safe code.
use once_self_cell::sync_once_self_cell;use std::cell::Cell;structOwner(Cell<&'staticstr>);structBorrowed<'a>(Cell<&'astr>);impl<'a>From<&'aOwner>forBorrowed<'a>{fnfrom(owner:&'aOwner) -> Borrowed<'a>{let r = owner.0.get();Borrowed(Cell::new(r))}}sync_once_self_cell!(SelfRef,Owner,Borrowed<'_>,);fndo_evil(cell:&SelfRef){let str = String::from("short lived");let dep = cell.get_or_init_dependent();
dep.0.set(&str);}fnmain(){let cell = SelfRef::new(Owner(Cell::new("static string")));do_evil(&cell);let dep = cell.get_or_init_dependent();println!("string: {:?}", dep.0.get());}
The text was updated successfully, but these errors were encountered:
Filing to track @jDomantas's report in https://www.reddit.com/r/rust/comments/m42fjx/safetouse_procmacrofree_selfreferential_structs/gqt6jkm/.
The signature of
get_or_init_dependent
improperly permits the caller to pick an arbitrarily short lifetime'a
, and then put a reference that is only live for'a
intoDependent
. Then it's possible for them to later pick a longer lifetime'b
and get aDependent<'b>
back out, leading to Use After Free or other undefined behavior in safe code.The text was updated successfully, but these errors were encountered: