Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 820123a

Browse files
committedMay 7, 2021
panic/fork: Command: Do not unwind after fork() in child
Unwinding after fork() in the child is UB on some platforms, because on those (including musl) malloc can be UB in the child of a multithreaded program, and unwinding must box for the payload. Even if it's safe, unwinding past fork() in the child causes whatever traps the unwind to return twice. This is very strange and clearly not desirable. With the default behaviour of the thread library, this can even result in a panic in the child being transformed into zero exit status (ie, success) as seen in the parent! Fixes #79740. Signed-off-by: Ian Jackson <[email protected]>
1 parent 3cba120 commit 820123a

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed
 

‎library/std/src/sys/unix/process/process_unix.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl Command {
5454
let (env_lock, pid) = unsafe { (sys::os::env_read_lock(), cvt(libc::fork())?) };
5555

5656
if pid == 0 {
57+
crate::panic::always_abort();
5758
mem::forget(env_lock);
5859
drop(input);
5960
let Err(err) = unsafe { self.do_exec(theirs, envp.as_ref()) };

0 commit comments

Comments
 (0)
Please sign in to comment.