From e31658b9145ccab8063bea486528a1fa3ef3d834 Mon Sep 17 00:00:00 2001 From: "Dongjia \"toka\" Zhang" Date: Thu, 16 May 2024 14:27:14 +0200 Subject: [PATCH] Change when to setup the ctrl c handler. (#2198) * copy * fmt * aa * a * Goodbye z3, i hope i won't build you forever * doc * fmt * fix * aa --- libafl/src/events/llmp.rs | 19 +++++++++---------- libafl/src/events/simple.rs | 18 ++++++++---------- libafl/src/events/tcp.rs | 18 ++++++++---------- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/libafl/src/events/llmp.rs b/libafl/src/events/llmp.rs index 983990ae1b..434dd1dad9 100644 --- a/libafl/src/events/llmp.rs +++ b/libafl/src/events/llmp.rs @@ -1556,6 +1556,7 @@ where handle.status() } ForkResult::Child => { + println!("AAA!"); self.shmem_provider.post_fork(true)?; break (staterestorer, self.shmem_provider.clone(), core_id); } @@ -1607,16 +1608,6 @@ where ctr = ctr.wrapping_add(1); } } else { - // At this point we are the fuzzer *NOT* the restarter. - // We setup signal handlers to clean up shmem segments used by state restorer - #[cfg(all(unix, not(miri)))] - if let Err(_e) = - unsafe { setup_signal_handler(addr_of_mut!(EVENTMGR_SIGHANDLER_STATE)) } - { - // We can live without a proper ctrl+c signal handler. Print and ignore. - log::error!("Failed to setup signal handlers: {_e}"); - } - // We are the newly started fuzzing instance (i.e. on Windows), first, connect to our own restore map. // We get here *only on Windows*, if we were started by a restarting fuzzer. // A staterestorer and a receiver for single communication @@ -1627,6 +1618,14 @@ where ) }; + // At this point we are the fuzzer *NOT* the restarter. + // We setup signal handlers to clean up shmem segments used by state restorer + #[cfg(all(unix, not(miri)))] + if let Err(_e) = unsafe { setup_signal_handler(addr_of_mut!(EVENTMGR_SIGHANDLER_STATE)) } { + // We can live without a proper ctrl+c signal handler. Print and ignore. + log::error!("Failed to setup signal handlers: {_e}"); + } + if let Some(core_id) = core_id { let core_id: CoreId = core_id; core_id.set_affinity()?; diff --git a/libafl/src/events/simple.rs b/libafl/src/events/simple.rs index f489d68bfe..28eefd8ed3 100644 --- a/libafl/src/events/simple.rs +++ b/libafl/src/events/simple.rs @@ -537,22 +537,20 @@ where ctr = ctr.wrapping_add(1); } } else { - // At this point we are the fuzzer *NOT* the restarter. - // We setup signal handlers to clean up shmem segments used by state restorer - #[cfg(all(unix, not(miri)))] - if let Err(_e) = - unsafe { setup_signal_handler(addr_of_mut!(EVENTMGR_SIGHANDLER_STATE)) } - { - // We can live without a proper ctrl+c signal handler. Print and ignore. - log::error!("Failed to setup signal handlers: {_e}"); - } - // We are the newly started fuzzing instance (i.e. on Windows), first, connect to our own restore map. // We get here *only on Windows*, if we were started by a restarting fuzzer. // A staterestorer and a receiver for single communication StateRestorer::from_env(shmem_provider, _ENV_FUZZER_SENDER)? }; + // At this point we are the fuzzer *NOT* the restarter. + // We setup signal handlers to clean up shmem segments used by state restorer + #[cfg(all(unix, not(miri)))] + if let Err(_e) = unsafe { setup_signal_handler(addr_of_mut!(EVENTMGR_SIGHANDLER_STATE)) } { + // We can live without a proper ctrl+c signal handler. Print and ignore. + log::error!("Failed to setup signal handlers: {_e}"); + } + // If we're restarting, deserialize the old state. let (state, mgr) = match staterestorer.restore::<(S, Duration, Vec)>()? { None => { diff --git a/libafl/src/events/tcp.rs b/libafl/src/events/tcp.rs index 09d9efbaf8..3a49c4f6f0 100644 --- a/libafl/src/events/tcp.rs +++ b/libafl/src/events/tcp.rs @@ -1295,16 +1295,6 @@ where ctr = ctr.wrapping_add(1); } } else { - // At this point we are the fuzzer *NOT* the restarter. - // We setup signal handlers to clean up shmem segments used by state restorer - #[cfg(all(unix, not(miri)))] - if let Err(_e) = - unsafe { setup_signal_handler(addr_of_mut!(EVENTMGR_SIGHANDLER_STATE)) } - { - // We can live without a proper ctrl+c signal handler. Print and ignore. - log::error!("Failed to setup signal handlers: {_e}"); - } - // We are the newly started fuzzing instance (i.e. on Windows), first, connect to our own restore map. // We get here *only on Windows*, if we were started by a restarting fuzzer. // A staterestorer and a receiver for single communication @@ -1315,6 +1305,14 @@ where ) }; + // At this point we are the fuzzer *NOT* the restarter. + // We setup signal handlers to clean up shmem segments used by state restorer + #[cfg(all(unix, not(miri)))] + if let Err(_e) = unsafe { setup_signal_handler(addr_of_mut!(EVENTMGR_SIGHANDLER_STATE)) } { + // We can live without a proper ctrl+c signal handler. Print and ignore. + log::error!("Failed to setup signal handlers: {_e}"); + } + if let Some(core_id) = core_id { let core_id: CoreId = core_id; core_id.set_affinity()?;