- Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
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-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.
Description
The args
method is defined as follows.
pub fn args() -> Args { let args = unsafe { (ARGS.load(Ordering::Relaxed) as *const ArgsStore).as_ref() }; if let Some(args) = args { Args(args.iter()) } else { Args([].iter()) } }
Clean-up function is defined as follows;
pub unsafe fn cleanup() { let args = ARGS.swap(0, Ordering::Relaxed); if args != 0 { drop(Box::<ArgsStore>::from_raw(args as _)) } }
It is possible for another thread to use std::env::args()
while the main thread quits, and access already freed memory - assuming the following sequence of events.
// Secondary thread let args = unsafe { (ARGS.load(Ordering::Relaxed) as *const ArgsStore).as_ref() }; // Main thread { let args = ARGS.swap(0, Ordering::Relaxed); if args != 0 { drop(Box::<ArgsStore>::from_raw(args as _)) } } // Secondary thread if let Some(args) = args { Args(args.iter()) }
This issue has been assigned to @Goirad via this comment.
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-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.