-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed as duplicate of#25860
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
I tried this code:
fn static_str_identity()
-> for<'s> fn(&'s str) -> (
[&'static &'s (); 0],
&'static str,
)
{
|s: &str| (
[],
s,
)
}
fn main()
{
let f = static_str_identity();
let local = String::from("123");
let s: &'static str = f(&local).1; // <- should be rejected!
drop(local);
let _unrelated = String::from("UAF!");
dbg!(s); // <- compiles and prints `"UAF!"`
}
I expected to see this happen: argument requires that s
is borrowed for 'static
Instead, this happened: code compiles successfully and the excution potentially triggers Use-After-Free on the String local
.
rogram returned: 0
Program stderr
[/app/example.rs:21:5] s = "UAF!"
This seems very much like a Use-After-Free issue, and it's quite likely related to the compiler.It can be reproduced in the latest version of the Rust compiler.
- Demo: godbolt permalink
- Demo: on current playground
rustc --version --verbose
:
rustc 1.84.0-nightly (c1db4dc24 2024-10-25)
note: This issue appears to be different from #114936, which was related to the Fn*
Trait and was fixed in version 1.78; whereas this problem can still trigger a vulnerability in the latest version.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.