diff --git a/libafl/src/executors/forkserver.rs b/libafl/src/executors/forkserver.rs index bfa11ed5ff..f653f7f5a7 100644 --- a/libafl/src/executors/forkserver.rs +++ b/libafl/src/executors/forkserver.rs @@ -309,6 +309,7 @@ impl Forkserver { memlimit: u64, is_persistent: bool, is_deferred_frksrv: bool, + coverage_map_size: Option, debug_output: bool, ) -> Result { Self::with_kill_signal( @@ -320,6 +321,7 @@ impl Forkserver { memlimit, is_persistent, is_deferred_frksrv, + coverage_map_size, debug_output, KILL_SIGNAL_DEFAULT, ) @@ -338,15 +340,20 @@ impl Forkserver { memlimit: u64, is_persistent: bool, is_deferred_frksrv: bool, + coverage_map_size: Option, debug_output: bool, kill_signal: Signal, ) -> Result { + let Some(coverage_map_size) = coverage_map_size else { + return Err(Error::unknown("Coverage map size unknown. Use coverage_map_size() to tell the forkserver about the map size.")); + }; + if env::var("AFL_MAP_SIZE").is_err() { log::warn!("AFL_MAP_SIZE not set. If it is unset, the forkserver may fail to start up"); } if env::var("__AFL_SHM_ID").is_err() { - log::warn!("__AFL_SHM_ID not set. It is necessary to set this env, otherwise the forkserver cannot communicate with the fuzzer"); + return Err(Error::unknown("__AFL_SHM_ID not set. It is necessary to set this env, otherwise the forkserver cannot communicate with the fuzzer".to_string())); } let mut st_pipe = Pipe::new().unwrap(); @@ -366,6 +373,8 @@ impl Forkserver { .stdout(stdout) .stderr(stderr); + command.env("AFL_MAP_SIZE", format!("{coverage_map_size}")); + // Persistent, deferred forkserver if is_persistent { command.env("__AFL_PERSISTENT", "1"); @@ -813,6 +822,7 @@ where 0, self.is_persistent, self.is_deferred_frksrv, + self.map_size, self.debug_child, self.kill_signal.unwrap_or(KILL_SIGNAL_DEFAULT), )?, @@ -1515,6 +1525,7 @@ mod tests { let executor = ForkserverExecutor::builder() .program(bin) .args(args) + .coverage_map_size(MAP_SIZE) .debug_child(false) .shmem_provider(&mut shmem_provider) .build::<_, ()>(tuple_list!(edges_observer));