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 <ijackson@chiark.greenend.org.uk>
This commit is contained in:
parent
3cba120ba4
commit
820123a949
1 changed files with 1 additions and 0 deletions
|
@ -54,6 +54,7 @@ impl Command {
|
|||
let (env_lock, pid) = unsafe { (sys::os::env_read_lock(), cvt(libc::fork())?) };
|
||||
|
||||
if pid == 0 {
|
||||
crate::panic::always_abort();
|
||||
mem::forget(env_lock);
|
||||
drop(input);
|
||||
let Err(err) = unsafe { self.do_exec(theirs, envp.as_ref()) };
|
||||
|
|
Loading…
Reference in a new issue