Skip to content

Commit

Permalink
add crash_exitcode to Forkserver to accomodate AFL_CRASH_EXITCODE (AF…
Browse files Browse the repository at this point in the history
…Lplusplus#2107)

* add crash_exitcode to Forkserver to accomodate AFL_CRASH_EXITCODE

* make crash_exitcode i8

---------

Co-authored-by: aarnav <[email protected]>
  • Loading branch information
R9295 and R9295 authored Apr 26, 2024
1 parent c2e0e8d commit 32963be
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion libafl/src/executors/forkserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ where
phantom: PhantomData<S>,
map_size: Option<usize>,
timeout: TimeSpec,
crash_exitcode: Option<i8>,
}

impl<OT, S, SP> Debug for ForkserverExecutor<OT, S, SP>
Expand Down Expand Up @@ -583,6 +584,7 @@ pub struct ForkserverExecutorBuilder<'a, SP> {
real_map_size: i32,
kill_signal: Option<Signal>,
timeout: Option<Duration>,
crash_exitcode: Option<i8>,
}

impl<'a, SP> ForkserverExecutorBuilder<'a, SP> {
Expand Down Expand Up @@ -631,6 +633,7 @@ impl<'a, SP> ForkserverExecutorBuilder<'a, SP> {
phantom: PhantomData,
map_size: self.map_size,
timeout,
crash_exitcode: self.crash_exitcode,
})
}

Expand Down Expand Up @@ -688,6 +691,7 @@ impl<'a, SP> ForkserverExecutorBuilder<'a, SP> {
phantom: PhantomData,
map_size: self.map_size,
timeout,
crash_exitcode: self.crash_exitcode,
})
}

Expand Down Expand Up @@ -999,6 +1003,13 @@ impl<'a, SP> ForkserverExecutorBuilder<'a, SP> {
self
}

/// Treats an execution as a crash if the provided exitcode is returned
#[must_use]
pub fn crash_exitcode(mut self, exitcode: i8) -> Self {
self.crash_exitcode = Some(exitcode);
self
}

/// Call this if the harness uses deferred forkserver mode; default is false
#[must_use]
pub fn is_deferred_frksrv(mut self, is_deferred_frksrv: bool) -> Self {
Expand Down Expand Up @@ -1047,6 +1058,7 @@ impl<'a> ForkserverExecutorBuilder<'a, UnixShMemProvider> {
max_input_size: MAX_INPUT_SIZE_DEFAULT,
kill_signal: None,
timeout: None,
crash_exitcode: None,
}
}

Expand All @@ -1072,6 +1084,7 @@ impl<'a> ForkserverExecutorBuilder<'a, UnixShMemProvider> {
max_input_size: MAX_INPUT_SIZE_DEFAULT,
kill_signal: None,
timeout: None,
crash_exitcode: None,
}
}
}
Expand Down Expand Up @@ -1157,7 +1170,12 @@ where

if let Some(status) = self.forkserver.read_st_timed(&self.timeout)? {
self.forkserver.set_status(status);
if libc::WIFSIGNALED(self.forkserver().status()) {
let exitcode_is_crash = if let Some(crash_exitcode) = self.crash_exitcode {
(libc::WEXITSTATUS(self.forkserver().status()) as i8) == crash_exitcode
} else {
false
};
if libc::WIFSIGNALED(self.forkserver().status()) || exitcode_is_crash {
exit_kind = ExitKind::Crash;
#[cfg(feature = "regex")]
if let Some(asan_observer) = self
Expand Down

0 comments on commit 32963be

Please sign in to comment.