Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add force-remove option #166

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
.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 @@
} 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())
})?;

Check warning on line 312 in casr/src/bin/casr-ubsan.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/bin/casr-ubsan.rs#L308-L312

Added lines #L308 - L312 were not covered by tests
} else {
bail!("Output directory is not empty.");

Check warning on line 314 in casr/src/bin/casr-ubsan.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/bin/casr-ubsan.rs#L314

Added line #L314 was not covered by tests
}
}
// 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 @@
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)?;

Check warning on line 322 in casr/src/util.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/util.rs#L321-L322

Added lines #L321 - L322 were not covered by tests
fs::create_dir_all(output_dir).with_context(|| {
format!("Couldn't create output directory {}", output_dir.display())
})?;

Check warning on line 325 in casr/src/util.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/util.rs#L324-L325

Added lines #L324 - L325 were not covered by tests
} else {
bail!("Output directory is not empty.");

Check warning on line 327 in casr/src/util.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/util.rs#L327

Added line #L327 was not covered by tests
}
}
// 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
Loading