diff --git a/vm_dump.c b/vm_dump.c index 5c79e80352..9c7227b3d7 100644 --- a/vm_dump.c +++ b/vm_dump.c @@ -1021,6 +1021,17 @@ rb_vm_bugreport(const void *ctx) } } + // Thread unsafe best effort attempt to stop printing the bug report in an + // infinite loop. Can happen with corrupt Ruby stack. + { + static bool crashing = false; + if (crashing) { + fprintf(stderr, "Crashed while printing bug report\n"); + return; + } + crashing = true; + } + #ifdef __linux__ # define PROC_MAPS_NAME "/proc/self/maps" #endif