@@ -391,6 +391,7 @@ pub mod panic_count {
391391 pub fn increase ( run_panic_hook : bool ) -> Option < MustAbort > {
392392 let global_count = GLOBAL_PANIC_COUNT . fetch_add ( 1 , Ordering :: Relaxed ) ;
393393 if global_count & ALWAYS_ABORT_FLAG != 0 {
394+ // Do *not* access thread-local state, we might be after a `fork`.
394395 return Some ( MustAbort :: AlwaysAbort ) ;
395396 }
396397
@@ -744,19 +745,22 @@ fn rust_panic_with_hook(
744745 if let Some ( must_abort) = must_abort {
745746 match must_abort {
746747 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) ) ;
749753 let panicinfo = PanicInfo :: internal_constructor (
750- None , // no message
751- location, // but we want to show the location!
754+ message. as_ref ( ) ,
755+ location,
752756 can_unwind,
753757 force_no_backtrace,
754758 ) ;
755759 rtprintpanic ! ( "{panicinfo}\n thread panicked while processing panic. aborting.\n " ) ;
756760 }
757761 panic_count:: MustAbort :: AlwaysAbort => {
758762 // 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.
760764 let panicinfo = PanicInfo :: internal_constructor (
761765 message,
762766 location,
0 commit comments