Skip to content

Commit

Permalink
Document AnyLifetime is unsound
Browse files Browse the repository at this point in the history
Summary: Using dtolnay example from [workplace](https://fb.workplace.com/groups/buck2eng/posts/2988664691431011).

Reviewed By: krallin

Differential Revision: D42516983

fbshipit-source-id: 839b8f0a67000b133154ddc4a116dfc1ed159155
  • Loading branch information
stepancheg authored and facebook-github-bot committed Jan 16, 2023
1 parent 4c46f5d commit 60fb0e9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gazebo/gazebo/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,15 @@ mod tests {
#[derive(ProvidesStaticType)]
struct FooBar<'x, P: My<'x>>(&'x P);
}

#[test]
fn test_any_lifetime_unsound() {
fn _use_after_free(s: &mut &str) {
let ss = (s as &mut dyn AnyLifetime).downcast_mut().unwrap();
// We allocate a string here, but do not store it anywhere, so it is dropped.
// But the pointer to it is available in `s` at call site.
// This is use after free.
*ss = &".".repeat(40);
}
}
}

0 comments on commit 60fb0e9

Please sign in to comment.