From 404227d1a3cac9980a4156bb903817186fb51d8b Mon Sep 17 00:00:00 2001 From: "Dongjia \"toka\" Zhang" Date: Mon, 10 Feb 2025 10:56:07 +0100 Subject: [PATCH] Don't panic inside sig handler (#2958) * fix_handler * hello * fmt --------- Co-authored-by: Your Name --- libafl/src/executors/hooks/unix.rs | 16 ++++++++-------- libafl/src/executors/hooks/windows.rs | 26 +++++++++++++------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libafl/src/executors/hooks/unix.rs b/libafl/src/executors/hooks/unix.rs index d0575c8d9f..536e144d11 100644 --- a/libafl/src/executors/hooks/unix.rs +++ b/libafl/src/executors/hooks/unix.rs @@ -53,10 +53,10 @@ pub mod unix_signal_handler { let data = &raw mut GLOBAL_STATE; let in_handler = (*data).set_in_handler(true); - assert!( - !in_handler, - "We crashed inside a crash handler, but this should never happen!" - ); + if in_handler { + log::error!("We crashed inside a crash handler, but this should never happen!"); + libc::exit(56); + } match signal { Signal::SigUser2 | Signal::SigAlarm => { @@ -98,10 +98,10 @@ pub mod unix_signal_handler { let data = &raw mut GLOBAL_STATE; let in_handler = (*data).set_in_handler(true); - assert!( - !in_handler, - "We crashed inside a crash panic hook, but this should never happen!" - ); + if in_handler { + log::error!("We crashed inside a crash panic hook, but this should never happen!"); + libc::exit(56); + } if (*data).is_valid() { // We are fuzzing! diff --git a/libafl/src/executors/hooks/windows.rs b/libafl/src/executors/hooks/windows.rs index 9472c122ed..d5e2e0c2de 100644 --- a/libafl/src/executors/hooks/windows.rs +++ b/libafl/src/executors/hooks/windows.rs @@ -5,7 +5,7 @@ pub mod windows_asan_handler { use core::sync::atomic::{compiler_fence, Ordering}; use windows::Win32::System::Threading::{ - EnterCriticalSection, LeaveCriticalSection, CRITICAL_SECTION, + EnterCriticalSection, ExitProcess, LeaveCriticalSection, CRITICAL_SECTION, }; use crate::{ @@ -36,10 +36,10 @@ pub mod windows_asan_handler { let data = &raw mut GLOBAL_STATE; let in_handler = (*data).set_in_handler(true); - assert!( - !in_handler, - "We crashed inside a asan death handler, but this should never happen!" - ); + if in_handler { + log::error!("We crashed inside a asan death handler, but this should never happen!"); + ExitProcess(56); + } // Have we set a timer_before? if (*data).ptp_timer.is_some() { @@ -166,10 +166,10 @@ pub mod windows_exception_handler { let data = &raw mut GLOBAL_STATE; let in_handler = (*data).set_in_handler(true); - assert!( - !in_handler, - "We crashed inside a crash handler, but this should never happen!" - ); + if in_handler { + log::error!("We crashed inside a crash handler, but this should never happen!"); + ExitProcess(56); + } if !(*data).crash_handler.is_null() { let func: HandlerFuncPtr = transmute((*data).crash_handler); @@ -206,10 +206,10 @@ pub mod windows_exception_handler { let data = &raw mut GLOBAL_STATE; let in_handler = (*data).set_in_handler(true); - assert!( - !in_handler, - "We crashed inside a panic hook, but this should never happen!" - ); + if in_handler { + log::error!("We crashed inside a crash handler, but this should never happen!"); + ExitProcess(56); + } // Have we set a timer_before? if (*data).ptp_timer.is_some() {