launchers without brokers (fixes #128) (#157)

This commit is contained in:
Dominik Maier 2021-06-08 15:40:32 +02:00 committed by GitHub
parent 4271790cb5
commit 24beae99f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,6 +36,7 @@ use typed_builder::TypedBuilder;
pub type LauncherClientFnRef<'a, I, OT, S, SP> = pub type LauncherClientFnRef<'a, I, OT, S, SP> =
&'a mut dyn FnMut(Option<S>, LlmpRestartingEventManager<I, OT, S, SP>) -> Result<(), Error>; &'a mut dyn FnMut(Option<S>, LlmpRestartingEventManager<I, OT, S, SP>) -> Result<(), Error>;
const _AFL_LAUNCHER_CLIENT: &str = "AFL_LAUNCHER_CLIENT";
/// Provides a Launcher, which can be used to launch a fuzzing run on a specified list of cores /// Provides a Launcher, which can be used to launch a fuzzing run on a specified list of cores
#[cfg(feature = "std")] #[cfg(feature = "std")]
#[derive(TypedBuilder)] #[derive(TypedBuilder)]
@ -54,7 +55,7 @@ where
stats: ST, stats: ST,
/// The 'main' function to run for each client forked. This probably shouldn't return /// The 'main' function to run for each client forked. This probably shouldn't return
run_client: LauncherClientFnRef<'a, I, OT, S, SP>, run_client: LauncherClientFnRef<'a, I, OT, S, SP>,
/// The broker port to use /// The broker port to use (or to attach to, in case [`Self::with_broker`] is `false`)
#[builder(default = 1337_u16)] #[builder(default = 1337_u16)]
broker_port: u16, broker_port: u16,
/// The list of cores to run on /// The list of cores to run on
@ -66,6 +67,12 @@ where
/// clusters. /// clusters.
#[builder(default = None)] #[builder(default = None)]
remote_broker_addr: Option<SocketAddr>, remote_broker_addr: Option<SocketAddr>,
/// If this launcher should spawn a new `broker` on `[Self::broker_port]` (default).
/// The reason you may not want this is, if you already have a [`Launcher`]
/// with a different configuration (for the same target) running on this machine.
/// Then, clients launched by this [`Launcher`] can connect to the original `broker`.
#[builder(default = true)]
spawn_broker: bool,
} }
#[cfg(feature = "std")] #[cfg(feature = "std")]
@ -128,6 +135,8 @@ where
}; };
} }
} }
if self.spawn_broker {
#[cfg(feature = "std")] #[cfg(feature = "std")]
println!("I am broker!!."); println!("I am broker!!.");
@ -147,6 +156,18 @@ where
libc::kill(*handle, libc::SIGINT); libc::kill(*handle, libc::SIGINT);
} }
} }
} else {
for handle in &handles {
let mut status = 0;
println!("Not spawning broker (spawn_broker is false). Waiting for fuzzer children to exit...");
unsafe {
libc::waitpid(*handle, &mut status, 0);
if status != 0 {
println!("Client with pid {} exited with status {}", handle, status);
}
}
}
}
Ok(()) Ok(())
} }
@ -215,6 +236,7 @@ where
Err(_) => panic!("Env variables are broken, received non-unicode!"), Err(_) => panic!("Env variables are broken, received non-unicode!"),
}; };
if self.spawn_broker {
#[cfg(feature = "std")] #[cfg(feature = "std")]
println!("I am broker!!."); println!("I am broker!!.");
@ -231,9 +253,16 @@ where
for handle in &mut handles { for handle in &mut handles {
handle.kill()?; handle.kill()?;
} }
} else {
println!("Not spawning broker (spawn_broker is false). Waiting for fuzzer children to exit...");
for handle in &mut handles {
let ecode = handle.wait()?;
if !ecode.success() {
println!("Client with handle {:?} exited with {:?}", handle, ecode);
}
}
}
Ok(()) Ok(())
} }
} }
const _AFL_LAUNCHER_CLIENT: &str = "AFL_LAUNCHER_CLIENT";