Skip to content

Commit 48463d0

Browse files
authored
Fix error handling in libafl_qemu_build (#2036)
* fix(libafl_qemu_build): assert command success * fix(libafl_qemu_build): make sure linker_interceptor.py picks up correct compiler Currently linker_interceptor.py uses 'cc' as the __LIBAFL_QEMU_BUILD_CC environment variable is never set * remove redudant arg
1 parent 0d5c621 commit 48463d0

File tree

1 file changed

+28
-22
lines changed
  • libafl_qemu/libafl_qemu_build/src

1 file changed

+28
-22
lines changed

libafl_qemu/libafl_qemu_build/src/build.rs

+28-22
Original file line numberDiff line numberDiff line change
@@ -84,34 +84,38 @@ pub fn build(
8484
if !qemu_path.is_dir() {
8585
println!("cargo:warning=Qemu not found, cloning with git ({QEMU_REVISION})...");
8686
fs::create_dir_all(&qemu_path).unwrap();
87-
Command::new("git")
87+
assert!(Command::new("git")
8888
.current_dir(&qemu_path)
8989
.arg("init")
9090
.status()
91-
.unwrap();
92-
Command::new("git")
91+
.unwrap()
92+
.success());
93+
assert!(Command::new("git")
9394
.current_dir(&qemu_path)
9495
.arg("remote")
9596
.arg("add")
9697
.arg("origin")
9798
.arg(QEMU_URL)
9899
.status()
99-
.unwrap();
100-
Command::new("git")
100+
.unwrap()
101+
.success());
102+
assert!(Command::new("git")
101103
.current_dir(&qemu_path)
102104
.arg("fetch")
103105
.arg("--depth")
104106
.arg("1")
105107
.arg("origin")
106108
.arg(QEMU_REVISION)
107109
.status()
108-
.unwrap();
109-
Command::new("git")
110+
.unwrap()
111+
.success());
112+
assert!(Command::new("git")
110113
.current_dir(&qemu_path)
111114
.arg("checkout")
112115
.arg("FETCH_HEAD")
113116
.status()
114-
.unwrap();
117+
.unwrap()
118+
.success());
115119
fs::write(&qemu_rev, QEMU_REVISION).unwrap();
116120
}
117121

@@ -290,22 +294,24 @@ pub fn build(
290294
.arg("--disable-tests");
291295
}
292296

293-
cmd.status().expect("Configure failed");
297+
assert!(
298+
cmd.status().expect("Invoking Configure failed").success(),
299+
"Configure didn't finish successfully"
300+
);
301+
let mut cmd = Command::new("make");
302+
cmd.current_dir(&build_dir)
303+
.env("__LIBAFL_QEMU_BUILD_OUT", build_dir.join("linkinfo.json"))
304+
.env("__LIBAFL_QEMU_BUILD_CC", cc_compiler.path())
305+
.env("__LIBAFL_QEMU_BUILD_CXX", cpp_compiler.path())
306+
.arg("-j");
307+
294308
if let Some(j) = jobs {
295-
Command::new("make")
296-
.current_dir(&build_dir)
297-
.arg("-j")
298-
.arg(&format!("{j}"))
299-
.env("V", "1")
300-
.status()
301-
.expect("Make failed");
302-
} else {
303-
Command::new("make")
304-
.current_dir(&build_dir)
305-
.arg("-j")
306-
.status()
307-
.expect("Make failed");
309+
cmd.arg(&format!("{j}")).env("V", "1");
308310
}
311+
assert!(
312+
cmd.status().expect("Invoking Make Failed").success(),
313+
"Make didn't finish successfully"
314+
);
309315
}
310316

311317
/*

0 commit comments

Comments
 (0)