From 470cf3bc669a1947c0ee4d9c383115a61d7189b4 Mon Sep 17 00:00:00 2001 From: hkctkuy Date: Mon, 21 Aug 2023 19:06:49 +0300 Subject: [PATCH] fix error printing --- casr/src/bin/casr-afl.rs | 33 ++++++++-------- casr/src/bin/casr-libfuzzer.rs | 70 +++++++++++++++++----------------- 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/casr/src/bin/casr-afl.rs b/casr/src/bin/casr-afl.rs index 908be059..8e6bfafd 100644 --- a/casr/src/bin/casr-afl.rs +++ b/casr/src/bin/casr-afl.rs @@ -279,11 +279,11 @@ fn main() -> Result<()> { .join( || { crashes.par_iter().try_for_each(|(_, crash)| { - let Ok(_) = crash.run_casr(output_dir.as_path(), timeout) else { - // Disable util::log_progress - *counter.write().unwrap() = total; - bail!("Casr run error"); - }; + if let Err(e) = crash.run_casr(output_dir.as_path(), timeout) { + // Disable util::log_progress + *counter.write().unwrap() = total; + bail!(e); + }; *counter.write().unwrap() += 1; Ok::<(), anyhow::Error>(()) }) @@ -406,17 +406,18 @@ fn summarize_results( .join( || { crashes.par_iter().try_for_each(|crash| { - let Ok(_) = AflCrashInfo { - path: crash.to_path_buf(), - target_args: gdb_args.clone(), - at_index, - is_asan: false, - } - .run_casr(None, timeout) else { - // Disable util::log_progress - *counter.write().unwrap() = total; - bail!("Casr run error"); - }; + if let Err(e) = (AflCrashInfo { + path: crash.to_path_buf(), + target_args: gdb_args.clone(), + at_index, + is_asan: false, + }) + .run_casr(None, timeout) + { + // Disable util::log_progress + *counter.write().unwrap() = total; + bail!(e); + }; *counter.write().unwrap() += 1; Ok::<(), anyhow::Error>(()) }) diff --git a/casr/src/bin/casr-libfuzzer.rs b/casr/src/bin/casr-libfuzzer.rs index ee250657..61d3670c 100644 --- a/casr/src/bin/casr-libfuzzer.rs +++ b/casr/src/bin/casr-libfuzzer.rs @@ -180,44 +180,44 @@ fn main() -> Result<()> { custom_pool .join( || { - let Ok (_) = crashes.par_iter().try_for_each(|(crash, fname)| { - let mut casr_cmd = Command::new(tool); - if timeout != 0 { - casr_cmd.args(["-t".to_string(), timeout.to_string()]); - } - casr_cmd.args([ - "-o", - format!("{}.casrep", output_dir.join(fname).display()).as_str(), - "--", - ]); - if !atheris_asan_lib.is_empty() { - casr_cmd.arg("python3"); - casr_cmd.env("LD_PRELOAD", &atheris_asan_lib); - } - casr_cmd.args(argv.clone()); - casr_cmd.arg(crash); - debug!("{:?}", casr_cmd); + if let Err(e) = crashes.par_iter().try_for_each(|(crash, fname)| { + let mut casr_cmd = Command::new(tool); + if timeout != 0 { + casr_cmd.args(["-t".to_string(), timeout.to_string()]); + } + casr_cmd.args([ + "-o", + format!("{}.casrep", output_dir.join(fname).display()).as_str(), + "--", + ]); + if !atheris_asan_lib.is_empty() { + casr_cmd.arg("python3"); + casr_cmd.env("LD_PRELOAD", &atheris_asan_lib); + } + casr_cmd.args(argv.clone()); + casr_cmd.arg(crash); + debug!("{:?}", casr_cmd); - // Get output - let casr_output = casr_cmd - .output() - .with_context(|| format!("Couldn't launch {casr_cmd:?}"))?; + // Get output + let casr_output = casr_cmd + .output() + .with_context(|| format!("Couldn't launch {casr_cmd:?}"))?; - if !casr_output.status.success() { - let err = String::from_utf8_lossy(&casr_output.stderr); - if err.contains("Program terminated (no crash)") { - warn!("{}: no crash on input {}", tool, crash.display()); - } else { - error!("{} for input: {}", err.trim(), crash.display()); + if !casr_output.status.success() { + let err = String::from_utf8_lossy(&casr_output.stderr); + if err.contains("Program terminated (no crash)") { + warn!("{}: no crash on input {}", tool, crash.display()); + } else { + error!("{} for input: {}", err.trim(), crash.display()); + } } - } - *counter.write().unwrap() += 1; - Ok::<(), anyhow::Error>(()) - }) else { - // Disable util::log_progress - *counter.write().unwrap() = total; - bail!("Casr run error"); - }; + *counter.write().unwrap() += 1; + Ok::<(), anyhow::Error>(()) + }) { + // Disable util::log_progress + *counter.write().unwrap() = total; + bail!(e); + }; Ok(()) }, || util::log_progress(&counter, total),