mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-17 20:38:06 +00:00
verify libfuzzer targets at the start of the task (#752)
This commit is contained in:
@ -170,7 +170,15 @@ pub fn get_synced_dirs(
|
||||
fn register_cleanup(job_id: Uuid) -> Result<()> {
|
||||
let path = std::env::current_dir()?.join(job_id.to_string());
|
||||
atexit::register(move || {
|
||||
remove_dir_all(&path).expect("cleanup failed");
|
||||
// only cleaing up if the path exists upon exit
|
||||
if std::fs::metadata(&path).is_ok() {
|
||||
let result = remove_dir_all(&path);
|
||||
|
||||
// don't panic if the remove failed but the path is gone
|
||||
if result.is_err() && std::fs::metadata(&path).is_ok() {
|
||||
result.expect("cleanup failed");
|
||||
}
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
@ -38,10 +38,9 @@ pub async fn run(args: &clap::ArgMatches<'_>) -> Result<()> {
|
||||
.expect("invalid crash dir remote location");
|
||||
|
||||
let fuzzer = LibFuzzerFuzzTask::new(fuzz_config)?;
|
||||
fuzzer.check_libfuzzer().await?;
|
||||
let mut task_handles = vec![];
|
||||
|
||||
let fuzz_task = spawn(async move { fuzzer.managed_run().await });
|
||||
let fuzz_task = spawn(async move { fuzzer.run().await });
|
||||
|
||||
wait_for_dir(&crash_dir).await?;
|
||||
|
||||
|
@ -186,7 +186,7 @@ impl Config {
|
||||
match self {
|
||||
Config::LibFuzzerFuzz(config) => {
|
||||
fuzz::libfuzzer_fuzz::LibFuzzerFuzzTask::new(config)?
|
||||
.managed_run()
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
Config::LibFuzzerReport(config) => {
|
||||
|
@ -93,22 +93,19 @@ impl CoverageTask {
|
||||
Self { config, poller }
|
||||
}
|
||||
|
||||
async fn check_libfuzzer(&self) -> Result<()> {
|
||||
if self.config.check_fuzzer_help {
|
||||
let fuzzer = LibFuzzer::new(
|
||||
&self.config.target_exe,
|
||||
&self.config.target_options,
|
||||
&self.config.target_env,
|
||||
&self.config.common.setup_dir,
|
||||
);
|
||||
fuzzer.check_help().await?;
|
||||
}
|
||||
Ok(())
|
||||
pub async fn verify(&self) -> Result<()> {
|
||||
let fuzzer = LibFuzzer::new(
|
||||
&self.config.target_exe,
|
||||
&self.config.target_options,
|
||||
&self.config.target_env,
|
||||
&self.config.common.setup_dir,
|
||||
);
|
||||
fuzzer.verify(self.config.check_fuzzer_help, None).await
|
||||
}
|
||||
|
||||
pub async fn managed_run(&mut self) -> Result<()> {
|
||||
info!("starting libFuzzer coverage task");
|
||||
self.check_libfuzzer().await?;
|
||||
self.verify().await?;
|
||||
self.config.coverage.init_pull().await?;
|
||||
self.process().await
|
||||
}
|
||||
|
@ -79,13 +79,9 @@ impl LibFuzzerFuzzTask {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn managed_run(&self) -> Result<()> {
|
||||
self.check_libfuzzer().await?;
|
||||
self.run().await
|
||||
}
|
||||
|
||||
pub async fn run(&self) -> Result<()> {
|
||||
self.init_directories().await?;
|
||||
self.verify().await?;
|
||||
|
||||
let hb_client = self.config.common.init_heartbeat().await?;
|
||||
|
||||
@ -102,17 +98,22 @@ impl LibFuzzerFuzzTask {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn check_libfuzzer(&self) -> Result<()> {
|
||||
if self.config.check_fuzzer_help {
|
||||
let fuzzer = LibFuzzer::new(
|
||||
&self.config.target_exe,
|
||||
&self.config.target_options,
|
||||
&self.config.target_env,
|
||||
&self.config.common.setup_dir,
|
||||
);
|
||||
fuzzer.check_help().await?;
|
||||
pub async fn verify(&self) -> Result<()> {
|
||||
let mut directories = vec![self.config.inputs.path.clone()];
|
||||
if let Some(readonly_inputs) = &self.config.readonly_inputs {
|
||||
let mut dirs = readonly_inputs.iter().map(|x| x.path.clone()).collect();
|
||||
directories.append(&mut dirs);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
let fuzzer = LibFuzzer::new(
|
||||
&self.config.target_exe,
|
||||
&self.config.target_options,
|
||||
&self.config.target_env,
|
||||
&self.config.common.setup_dir,
|
||||
);
|
||||
fuzzer
|
||||
.verify(self.config.check_fuzzer_help, Some(directories))
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn run_fuzzers(&self, stats_sender: Option<&StatsSender>) -> Result<()> {
|
||||
@ -256,11 +257,11 @@ impl LibFuzzerFuzzTask {
|
||||
}
|
||||
|
||||
async fn init_directories(&self) -> Result<()> {
|
||||
self.config.inputs.init().await?;
|
||||
self.config.inputs.init_pull().await?;
|
||||
self.config.crashes.init().await?;
|
||||
if let Some(readonly_inputs) = &self.config.readonly_inputs {
|
||||
for dir in readonly_inputs {
|
||||
dir.init().await?;
|
||||
dir.init_pull().await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -47,15 +47,13 @@ pub struct Config {
|
||||
}
|
||||
|
||||
pub async fn spawn(config: Arc<Config>) -> Result<()> {
|
||||
if config.check_fuzzer_help {
|
||||
let target = LibFuzzer::new(
|
||||
&config.target_exe,
|
||||
&config.target_options,
|
||||
&config.target_env,
|
||||
&config.common.setup_dir,
|
||||
);
|
||||
target.check_help().await?;
|
||||
}
|
||||
let fuzzer = LibFuzzer::new(
|
||||
&config.target_exe,
|
||||
&config.target_options,
|
||||
&config.target_env,
|
||||
&config.common.setup_dir,
|
||||
);
|
||||
fuzzer.verify(config.check_fuzzer_help, None).await?;
|
||||
|
||||
config.unique_inputs.init().await?;
|
||||
if let Some(queue) = config.input_queue.clone() {
|
||||
|
@ -62,8 +62,19 @@ impl ReportTask {
|
||||
Self { config, poller }
|
||||
}
|
||||
|
||||
pub async fn verify(&self) -> Result<()> {
|
||||
let fuzzer = LibFuzzer::new(
|
||||
&self.config.target_exe,
|
||||
&self.config.target_options,
|
||||
&self.config.target_env,
|
||||
&self.config.common.setup_dir,
|
||||
);
|
||||
fuzzer.verify(self.config.check_fuzzer_help, None).await
|
||||
}
|
||||
|
||||
pub async fn managed_run(&mut self) -> Result<()> {
|
||||
info!("Starting libFuzzer crash report task");
|
||||
self.verify().await?;
|
||||
|
||||
if let Some(unique_reports) = &self.config.unique_reports {
|
||||
unique_reports.init().await?;
|
||||
|
Reference in New Issue
Block a user