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
use self_cell::self_cell;typeDep1<'a> = (&'a str,&'static str);self_cell!{pubstructStruct1{
owner: String,
#[covariant]
dependent: Dep1,
}}typeDep2<'a> = (&'static str,&'a str);self_cell!{pubstructStruct2{
owner: String,
#[covariant]
dependent: Dep2,
}}fnmain(){let hello:&'static str;{letmut x1 = Struct1::new(String::from("Hello World"), |s| (s,""));letmut x2 = Struct2::new(String::new(), |_| ("",""));
std::mem::swap(&mut x1.unsafe_self_cell,&mut x2.unsafe_self_cell);
hello = x2.borrow_dependent().0;dbg!(hello);// "Hello World"// hello is now a static reference in to the "Hello World" string}// the String is dropped at the end of the block abovedbg!(hello);// prints garbage, use-after-free}
The text was updated successfully, but these errors were encountered:
steffahn
changed the title
The unsafe_self_cell field is accessible, leading to unsound safe code
The unsafe_self_cell field is accessible, allowing UB from safe code
Sep 20, 2021
This release addresses two somewhat exotic ways self_cell could be used in an
unsound fashion to cause UB. See issues #17 and #18. Thanks @steffahn for
reporting and helping to fix these issues.
The text was updated successfully, but these errors were encountered: