@@ -391,6 +391,7 @@ pub mod panic_count {
391
391
pub fn increase ( run_panic_hook : bool ) -> Option < MustAbort > {
392
392
let global_count = GLOBAL_PANIC_COUNT . fetch_add ( 1 , Ordering :: Relaxed ) ;
393
393
if global_count & ALWAYS_ABORT_FLAG != 0 {
394
+ // Do *not* access thread-local state, we might be after a `fork`.
394
395
return Some ( MustAbort :: AlwaysAbort ) ;
395
396
}
396
397
@@ -744,19 +745,22 @@ fn rust_panic_with_hook(
744
745
if let Some ( must_abort) = must_abort {
745
746
match must_abort {
746
747
panic_count:: MustAbort :: PanicInHook => {
747
- // Don't try to print the message in this case
748
- // - perhaps that is causing the recursive panics.
748
+ // Don't try to format the message in this case, perhaps that is causing the
749
+ // recursive panics. However if the message is just a string, no user-defined
750
+ // code is involved in printing it, so that is risk-free.
751
+ let msg_str = message. and_then ( |m| m. as_str ( ) ) . map ( |m| [ m] ) ;
752
+ let message = msg_str. as_ref ( ) . map ( |m| fmt:: Arguments :: new_const ( m) ) ;
749
753
let panicinfo = PanicInfo :: internal_constructor (
750
- None , // no message
751
- location, // but we want to show the location!
754
+ message. as_ref ( ) ,
755
+ location,
752
756
can_unwind,
753
757
force_no_backtrace,
754
758
) ;
755
759
rtprintpanic ! ( "{panicinfo}\n thread panicked while processing panic. aborting.\n " ) ;
756
760
}
757
761
panic_count:: MustAbort :: AlwaysAbort => {
758
762
// Unfortunately, this does not print a backtrace, because creating
759
- // a `Backtrace` will allocate, which we must to avoid here.
763
+ // a `Backtrace` will allocate, which we must avoid here.
760
764
let panicinfo = PanicInfo :: internal_constructor (
761
765
message,
762
766
location,
0 commit comments