diff --git a/fuzzers/baby/baby_fuzzer_swap_differential/src/main.rs b/fuzzers/baby/baby_fuzzer_swap_differential/src/main.rs index 093468b685..5aed2191aa 100644 --- a/fuzzers/baby/baby_fuzzer_swap_differential/src/main.rs +++ b/fuzzers/baby/baby_fuzzer_swap_differential/src/main.rs @@ -203,7 +203,7 @@ pub fn main() { // The Monitor trait define how the fuzzer stats are displayed to the user #[cfg(not(feature = "tui"))] - let mon = SimpleMonitor::with_user_monitor(|s| println!("{s}")); + let mon = SimpleMonitor::new(|s| println!("{s}")); #[cfg(feature = "tui")] let mon = TuiMonitor::builder() .title("Baby Fuzzer") diff --git a/fuzzers/binary_only/fuzzbench_fork_qemu/src/fuzzer.rs b/fuzzers/binary_only/fuzzbench_fork_qemu/src/fuzzer.rs index cd0a0db063..23b55e1684 100644 --- a/fuzzers/binary_only/fuzzbench_fork_qemu/src/fuzzer.rs +++ b/fuzzers/binary_only/fuzzbench_fork_qemu/src/fuzzer.rs @@ -232,7 +232,7 @@ fn fuzz( let file_null = File::open("/dev/null")?; // 'While the stats are state, they are usually used in the broker - which is likely never restarted - let monitor = SimpleMonitor::with_user_monitor(|s| { + let monitor = SimpleMonitor::new(|s| { #[cfg(unix)] writeln!(&mut stdout_cpy, "{s}").unwrap(); #[cfg(windows)] diff --git a/fuzzers/binary_only/qemu_cmin/src/fuzzer.rs b/fuzzers/binary_only/qemu_cmin/src/fuzzer.rs index a63e840491..9df44305a4 100644 --- a/fuzzers/binary_only/qemu_cmin/src/fuzzer.rs +++ b/fuzzers/binary_only/qemu_cmin/src/fuzzer.rs @@ -180,7 +180,7 @@ pub fn fuzz() -> Result<(), Error> { let stack_ptr: GuestAddr = qemu.read_reg(Regs::Sp).unwrap(); - let monitor = SimpleMonitor::with_user_monitor(|s| { + let monitor = SimpleMonitor::new(|s| { println!("{s}"); }); let (state, mut mgr) = match SimpleRestartingEventManager::launch(monitor, &mut shmem_provider) diff --git a/fuzzers/binary_only/qemu_tmin/src/tmin_single_core.rs b/fuzzers/binary_only/qemu_tmin/src/tmin_single_core.rs index 03ba7591dd..4bf2015fdf 100644 --- a/fuzzers/binary_only/qemu_tmin/src/tmin_single_core.rs +++ b/fuzzers/binary_only/qemu_tmin/src/tmin_single_core.rs @@ -223,7 +223,7 @@ pub fn fuzz() -> Result<(), Error> { }; // Set up the most basic monitor possible. - let monitor = SimpleMonitor::with_user_monitor(|s| { + let monitor = SimpleMonitor::new(|s| { println!("{s}"); }); let (state, mut mgr) = match SimpleRestartingEventManager::launch(monitor, &mut shmem_provider) diff --git a/fuzzers/forkserver/forkserver_libafl_cc/src/main.rs b/fuzzers/forkserver/forkserver_libafl_cc/src/main.rs index e24e87d832..c710563645 100644 --- a/fuzzers/forkserver/forkserver_libafl_cc/src/main.rs +++ b/fuzzers/forkserver/forkserver_libafl_cc/src/main.rs @@ -149,7 +149,7 @@ pub fn main() { .unwrap(); // The Monitor trait define how the fuzzer stats are reported to the user - let monitor = SimpleMonitor::with_user_monitor(|s| { + let monitor = SimpleMonitor::new(|s| { println!("{s}"); }); diff --git a/libafl/src/monitors/mod.rs b/libafl/src/monitors/mod.rs index 5f38c7ed32..bde8280ce0 100644 --- a/libafl/src/monitors/mod.rs +++ b/libafl/src/monitors/mod.rs @@ -153,7 +153,6 @@ where F: FnMut(&str), { print_fn: F, - print_user_monitor: bool, } impl Debug for SimpleMonitor @@ -188,12 +187,10 @@ where global_stats.execs_per_sec_pretty ); - if self.print_user_monitor { - client_stats_manager.client_stats_insert(sender_id)?; - let client = client_stats_manager.client_stats_for(sender_id)?; - for (key, val) in client.user_stats() { - write!(fmt, ", {key}: {val}").unwrap(); - } + client_stats_manager.client_stats_insert(sender_id)?; + let client = client_stats_manager.client_stats_for(sender_id)?; + for (key, val) in client.user_stats() { + write!(fmt, ", {key}: {val}").unwrap(); } (self.print_fn)(&fmt); @@ -222,10 +219,7 @@ where { /// Creates the monitor, using the `current_time` as `start_time`. pub fn new(print_fn: F) -> Self { - Self { - print_fn, - print_user_monitor: false, - } + Self { print_fn } } /// Creates the monitor with a given `start_time`. @@ -236,14 +230,6 @@ where pub fn with_time(print_fn: F, _start_time: Duration) -> Self { Self::new(print_fn) } - - /// Creates the monitor that also prints the user monitor - pub fn with_user_monitor(print_fn: F) -> Self { - Self { - print_fn, - print_user_monitor: true, - } - } } /// Start the timer diff --git a/libafl_targets/build.rs b/libafl_targets/build.rs index b4467cd171..e9c12a3204 100644 --- a/libafl_targets/build.rs +++ b/libafl_targets/build.rs @@ -246,14 +246,14 @@ fn main() { let target_family = std::env::var("CARGO_CFG_TARGET_FAMILY").unwrap(); if target_family == "windows" { println!("cargo:rerun-if-changed=src/windows_asan.c"); - + let mut windows_asan = cc::Build::new(); - + #[cfg(feature = "whole_archive")] { windows_asan.link_lib_modifier("+whole-archive"); } - + windows_asan .file(src_dir.join("windows_asan.c")) .compile("windows_asan"); diff --git a/libafl_targets/src/forkserver.rs b/libafl_targets/src/forkserver.rs index 47b81812ca..1bde580568 100644 --- a/libafl_targets/src/forkserver.rs +++ b/libafl_targets/src/forkserver.rs @@ -1,12 +1,11 @@ //! Forkserver logic into targets +use core::sync::atomic::{AtomicBool, Ordering}; use std::{ os::fd::{AsFd, AsRawFd, BorrowedFd}, sync::OnceLock, }; -use core::sync::atomic::{AtomicBool, Ordering}; - use libafl::{ Error, executors::forkserver::{ @@ -15,7 +14,6 @@ use libafl::{ }, }; use libafl_bolts::os::{ChildHandle, ForkResult}; - use nix::{ sys::signal::{SigHandler, Signal}, unistd::Pid, @@ -293,11 +291,8 @@ impl ForkserverParent for MaybePersistentForkserverParent { // a child, wait it, and get a stopped signal. Moreover, was_killed is // true only if the forkserver killed such child. In all cases, the // last_child_pid will never be None. - if nix::sys::wait::waitpid( - Pid::from_raw(self.last_child_pid.take().unwrap()), - None, - ) - .is_err() + if nix::sys::wait::waitpid(Pid::from_raw(self.last_child_pid.take().unwrap()), None) + .is_err() { return Err(Error::illegal_state("child_stopped && was_killed")); } @@ -306,7 +301,7 @@ impl ForkserverParent for MaybePersistentForkserverParent { if self.child_stopped { // Special handling for persistent mode: if the child is alive but // currently stopped, simply restart it with SIGCONT. - + // unwrap here: child_stopped is true only if last_child_pid is some. let child_pid = *self.last_child_pid.as_ref().unwrap(); nix::sys::signal::kill(Pid::from_raw(child_pid), Signal::SIGCONT)?; @@ -323,15 +318,21 @@ impl ForkserverParent for MaybePersistentForkserverParent { } ForkResult::Child => unsafe { // unwrap here: the field is assigned in `pre_fuzzing` - nix::sys::signal::signal(Signal::SIGCHLD, self.old_sigchld_handler.take().unwrap()) - .inspect_err(|_| { - log::error!("Fail to restore signal handler for SIGCHLD."); - })?; + nix::sys::signal::signal( + Signal::SIGCHLD, + self.old_sigchld_handler.take().unwrap(), + ) + .inspect_err(|_| { + log::error!("Fail to restore signal handler for SIGCHLD."); + })?; // unwrap here: the field is assigned in `pre_fuzzing` - nix::sys::signal::signal(Signal::SIGTERM, self.old_sigterm_handler.take().unwrap()) - .inspect_err(|_| { - log::error!("Fail to restore signal handler for SIGTERM."); - })?; + nix::sys::signal::signal( + Signal::SIGTERM, + self.old_sigterm_handler.take().unwrap(), + ) + .inspect_err(|_| { + log::error!("Fail to restore signal handler for SIGTERM."); + })?; }, } Ok(fork_result) @@ -341,7 +342,8 @@ impl ForkserverParent for MaybePersistentForkserverParent { fn handle_child_requests(&mut self) -> Result { let mut status = 0i32; // unwrap here: the field is assigned if we are parent process in `spawn_child` - if unsafe { libc::waitpid(*self.last_child_pid.as_ref().unwrap(), &raw mut status, 0) < 0 } { + if unsafe { libc::waitpid(*self.last_child_pid.as_ref().unwrap(), &raw mut status, 0) < 0 } + { return Err(Error::illegal_state("waitpid")); } if libc::WIFSTOPPED(status) { diff --git a/scripts/clippy.sh b/scripts/clippy.sh index 473d254971..4f8de7bd37 100755 --- a/scripts/clippy.sh +++ b/scripts/clippy.sh @@ -75,4 +75,4 @@ eval "$CLIPPY_CMD --workspace -- $RUSTC_FLAGS" echo "Clippy run completed for all specified projects." # Last run it on all -eval "$CLIPPY_CMD --workspace -- $RUSTC_FLAGS" \ No newline at end of file +eval "$CLIPPY_CMD --workspace -- $RUSTC_FLAGS" diff --git a/scripts/test_fuzzer.sh b/scripts/test_fuzzer.sh index bf0670d595..6422704116 100755 --- a/scripts/test_fuzzer.sh +++ b/scripts/test_fuzzer.sh @@ -5,22 +5,11 @@ cd "$SCRIPT_DIR/.." || exit 1 # TODO: This should be rewritten in rust, a Makefile, or some platform-independent language -if [[ -z "${RUN_ON_CI}" ]]; then - fuzzers=$(find ./fuzzers -mindepth 1 -maxdepth 1 -type d) - backtrace_fuzzers=$(find ./fuzzers/backtrace_baby_fuzzers -mindepth 1 -maxdepth 1 -type d) - fuzzer_to_test="$fuzzers $backtrace_fuzzers" -else - fuzzer_to_test="$1" - export PROFILE=dev - export PROFILE_DIR=debug -fi +fuzzer_to_test="$1" +export PROFILE=dev +export PROFILE_DIR=debug echo "Testing" "$fuzzer_to_test" -# build with a shared target dir for all fuzzers. this should speed up -# compilation a bit, and allows for easier artifact management (caching and -# cargo clean). - -git submodule init && git submodule update # override default profile settings for speed # export RUSTFLAGS="-C prefer-dynamic"