Skip to content

Commit

Permalink
Add force-remove option (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkctkuy authored Oct 13, 2023
1 parent ccaddb9 commit 0ac3deb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
7 changes: 7 additions & 0 deletions casr/src/bin/casr-afl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ fn main() -> Result<()> {
.value_parser(clap::value_parser!(PathBuf))
.help("Output directory with triaged reports")
)
.arg(
Arg::new("force-remove")
.short('f')
.long("force-remove")
.action(ArgAction::SetTrue)
.help("Remove output project directory if it exists")
)
.arg(
Arg::new("ignore-cmdline")
.action(ArgAction::SetTrue)
Expand Down
7 changes: 7 additions & 0 deletions casr/src/bin/casr-libfuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ fn main() -> Result<()> {
.value_name("OUTPUT_DIR")
.help("Output directory with triaged reports")
)
.arg(
Arg::new("force-remove")
.short('f')
.long("force-remove")
.action(ArgAction::SetTrue)
.help("Remove output project directory if it exists")
)
.arg(
Arg::new("no-cluster")
.action(ArgAction::SetTrue)
Expand Down
16 changes: 15 additions & 1 deletion casr/src/bin/casr-ubsan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ fn main() -> Result<()> {
.value_parser(clap::value_parser!(PathBuf))
.help("Output directory with triaged reports")
)
.arg(
Arg::new("force-remove")
.short('f')
.long("force-remove")
.action(ArgAction::SetTrue)
.help("Remove output project directory if it exists")
)
.arg(
Arg::new("ARGS")
.action(ArgAction::Set)
Expand All @@ -298,7 +305,14 @@ fn main() -> Result<()> {
} else if !output_dir.is_dir() {
bail!("Output directory must be a directory");
} else if output_dir.read_dir()?.next().is_some() {
bail!("Output directory is not empty.");
if matches.get_flag("force-remove") {
fs::remove_dir_all(output_dir)?;
fs::create_dir_all(output_dir).with_context(|| {
format!("Couldn't create output directory {}", output_dir.display())
})?;
} else {
bail!("Output directory is not empty.");
}
}
// Get program args.
let argv: Vec<&str> = if let Some(argvs) = matches.get_many::<String>("ARGS") {
Expand Down
9 changes: 8 additions & 1 deletion casr/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,14 @@ pub fn initialize_dirs(matches: &clap::ArgMatches) -> Result<&PathBuf> {
format!("Couldn't create output directory {}", output_dir.display())
})?;
} else if output_dir.read_dir()?.next().is_some() {
bail!("Output directory is not empty.");
if matches.get_flag("force-remove") {
fs::remove_dir_all(output_dir)?;
fs::create_dir_all(output_dir).with_context(|| {
format!("Couldn't create output directory {}", output_dir.display())
})?;
} else {
bail!("Output directory is not empty.");
}
}
// Get oom dir
let oom_dir = output_dir.join("oom");
Expand Down
4 changes: 4 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Triage errors found by UndefinedBehaviorSanitizer and create CASR reports (.casr
that timeout is disabled [default: 0]
-i, --input <INPUT_DIRS>... Target input directory list
-o, --output <OUTPUT_DIR> Output directory with triaged reports
-f, --force-remove Remove output project directory if it exists
-h, --help Print help
-V, --version Print version

Expand Down Expand Up @@ -363,6 +364,7 @@ Triage crashes found by AFL++
that timeout is disabled [default: 0]
-i, --input <INPUT_DIR> AFL++ work directory
-o, --output <OUTPUT_DIR> Output directory with triaged reports
-f, --force-remove Remove output project directory if it exists
--ignore-cmdline Force <ARGS> usage to run target instead of searching for
cmdline files in AFL fuzzing directory
--no-cluster Do not cluster CASR reports
Expand Down Expand Up @@ -474,6 +476,8 @@ Triage crashes found by libFuzzer based fuzzer (C/C++/go-fuzz/Atheris/Jazzer)
Directory containing crashes found by libFuzzer [default: .]
-o, --output <OUTPUT_DIR>
Output directory with triaged reports
-f, --force-remove
Remove output project directory if it exists
--no-cluster
Do not cluster CASR reports
--casr-gdb-args <casr-gdb-args>
Expand Down

0 comments on commit 0ac3deb

Please sign in to comment.