Skip to content

Commit 3f5ac2d

Browse files
committed
Address feedback on new delete-nonreduced-fuzz-inputs script in rust
Addressed feedback: * use relative link in README * refactor argument parsing to be easier to extend * drops 'too many arguments' error message * Use ?; consistently * avoid temporary copy when building arguments for Command::new * replace wget with curl * also use --depth=1 when cloning AFLplusplus * use git add + git commit consistently instead of git commit -a * don't require -Znext-lockfile-bump with cargo Additionally: * fix git clone error message did not use format! macro * add .gitignore to ignore cargo target/
1 parent 26fe402 commit 3f5ac2d

File tree

4 files changed

+30
-27
lines changed

4 files changed

+30
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ runner:
2727

2828
To avoid corpora bloat, stale inputs and potential CI timeouts, we usually
2929
prune/minimize our corpora around the branch-off point using the
30-
[`delete-nonreduced-fuzz-inputs`](https://github.com/bitcoin-core/qa-assets/tree/main/delete-nonreduced-fuzz-inputs)
30+
[`delete-nonreduced-fuzz-inputs`](/delete-nonreduced-fuzz-inputs)
3131
script (Recommended to run in a fresh VM, see documentation in the script). The
3232
script is usually run twice to ensure that the results are "somewhat"
3333
reproducible (e.g.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

delete-nonreduced-fuzz-inputs/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

delete-nonreduced-fuzz-inputs/src/main.rs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,20 @@ Usage: delete-nonreduced-fuzz-inputs
6464
}
6565

6666
fn app() -> AppResult {
67-
let mut args = env::args().skip(1);
68-
match args.next() {
69-
None => {}
70-
Some(a) if a == "--help" || a == "-h" => {
71-
if args.next().is_some() {
72-
Err(help("Too many arguments"))?;
73-
}
74-
Err(help("help requested"))?;
67+
for arg in env::args().skip(1) {
68+
match arg.as_str() {
69+
"--help" | "-h" => return Err(help("help requested")),
70+
a => return Err(format!("Unexpected argument: {a}")),
7571
}
76-
Some(a) => Err(help(&format!("Unexpected argument: {a}")))?,
7772
}
73+
7874
install_deps()?;
7975
clone_and_configure_repositories()?;
8076

8177
let all_inputs_dir = move_fuzz_inputs()?;
82-
git_commit_all(QA_ASSETS_PATH, "Delete fuzz inputs")?;
78+
// git commit -a does not add untracked files so we use git add manually
79+
git_add(QA_ASSETS_PATH, FUZZ_CORPORA_DIR)?;
80+
git_commit(QA_ASSETS_PATH, "Delete fuzz inputs")?;
8381

8482
let fuzz_corpora_dir_path = Path::new(QA_ASSETS_PATH).join(FUZZ_CORPORA_DIR);
8583

@@ -95,16 +93,15 @@ fn app() -> AppResult {
9593
let output_dir = fuzz_corpora_dir_path.join(fuzz_target);
9694
run_afl_cmin(fuzz_target, input_dir, output_dir)?;
9795
}
98-
// git commit -a does not add untracked files so we add fuzz_corpora manually
9996
git_add(QA_ASSETS_PATH, FUZZ_CORPORA_DIR)?;
100-
git_commit_all(QA_ASSETS_PATH, "Reduced inputs for afl-cmin")?;
97+
git_commit(QA_ASSETS_PATH, "Reduced inputs for afl-cmin")?;
10198

10299
for sanitizer in SANITIZERS {
103100
println!("Adding reduced seeds for sanitizer={sanitizer}");
104101
build_bitcoin_with_sanitizer(sanitizer)?;
105102
run_libfuzzer(&all_inputs_dir, &fuzz_corpora_dir_path)?;
106103
git_add(QA_ASSETS_PATH, FUZZ_CORPORA_DIR)?;
107-
git_commit_all(QA_ASSETS_PATH, &format!("Reduced inputs for {sanitizer}"))?;
104+
git_commit(QA_ASSETS_PATH, &format!("Reduced inputs for {sanitizer}"))?;
108105
}
109106

110107
println!("✨ Saved minimized fuzz corpora. ✨");
@@ -114,7 +111,8 @@ fn app() -> AppResult {
114111
fn install_deps() -> AppResult {
115112
install_apt_deps()?;
116113
install_llvm()?;
117-
install_aflpp()
114+
install_aflpp()?;
115+
Ok(())
118116
}
119117

120118
fn install_apt_deps() -> AppResult {
@@ -129,10 +127,9 @@ fn install_apt_deps() -> AppResult {
129127
Err("apt update failed".to_string())?;
130128
}
131129

132-
let mut install_args: Vec<&str> = vec!["install", "-y"];
133-
install_args.extend_from_slice(APT_PACKAGES);
134130
if !Command::new("apt")
135-
.args(&install_args)
131+
.args(["install", "-y"])
132+
.args(APT_PACKAGES)
136133
.status()
137134
.map_err(|e| format!("failed to spawn apt: {e}"))?
138135
.success()
@@ -146,13 +143,18 @@ fn install_apt_deps() -> AppResult {
146143
fn install_llvm() -> AppResult {
147144
env::set_var("LLVM_VERSION", LLVM_VERSION);
148145

149-
if !Command::new("wget")
150-
.arg("https://apt.llvm.org/llvm.sh")
146+
if !Command::new("curl")
147+
.args([
148+
"--fail",
149+
"--location",
150+
"--remote-name",
151+
"https://apt.llvm.org/llvm.sh",
152+
])
151153
.status()
152-
.map_err(|e| format!("failed to spawn wget: {e}"))?
154+
.map_err(|e| format!("failed to spawn curl: {e}"))?
153155
.success()
154156
{
155-
Err("wget failed".to_string())?;
157+
Err("curl failed".to_string())?;
156158
}
157159

158160
if !Command::new("bash")
@@ -183,7 +185,7 @@ fn install_aflpp() -> AppResult {
183185
let clone_path = "AFLplusplus";
184186
git_clone(
185187
"https://github.com/AFLplusplus/AFLplusplus",
186-
&["--branch=stable"],
188+
&["--branch=stable", "--depth=1"],
187189
clone_path,
188190
)?;
189191
if !Command::new("make")
@@ -251,7 +253,7 @@ fn git_clone<P: AsRef<Path>>(url: &str, clone_args: &[&str], clone_path: P) -> A
251253
.map_err(|e| format!("failed to spawn git clone: {e}"))?
252254
.success()
253255
{
254-
return Err("git clone {url} failed".to_string());
256+
return Err(format!("git clone {url} failed"));
255257
}
256258

257259
Ok(())
@@ -286,10 +288,10 @@ fn git_add<P: AsRef<Path>, Q: AsRef<Path>>(repo_path: P, file_path: Q) -> AppRes
286288
Ok(())
287289
}
288290

289-
fn git_commit_all<P: AsRef<Path>>(repo_path: P, message: &str) -> AppResult {
291+
fn git_commit<P: AsRef<Path>>(repo_path: P, message: &str) -> AppResult {
290292
if !Command::new("git")
291293
.current_dir(repo_path)
292-
.args(["commit", "-a", "-m", message])
294+
.args(["commit", "-m", message])
293295
.status()
294296
.map_err(|e| format!("failed to spawn git commit: {e}"))?
295297
.success()

0 commit comments

Comments
 (0)