-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Footgun with catch_unwind when catching panic-on-drop types #86027
Copy link
Copy link
Open
Labels
A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsP-mediumMedium priorityMedium priorityT-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsP-mediumMedium priorityMedium priorityT-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Originally reported by @SabrinaJewson in #85927
catch_unwind(code)is often used to make sure no panics fromcodecan cause further unwinding/panics. However, when catching a panic with a payload that panics on Drop, most usages ofcatch_unwind(code)will still result in further unwinding and often unsoundness.Example in rustc (found by @mystor):
rust/compiler/rustc_ast/src/mut_visit.rs
Lines 299 to 300 in 5ea1923
Here, the
Resultcontaining the panic payload is dropped beforeabort()is called, which might cause a panic.Edit: Looks like the
_doesn't cause an immediate drop as a parameter, so this case works fine, possibly by accident.Another example in the standard library:
rust/library/std/src/rt.rs
Lines 34 to 39 in 5ea1923
And another case in the
proc_macrobridge:rust/library/proc_macro/src/bridge/server.rs
Lines 115 to 116 in 5ea1923