Skip to content

Commit d65c9cb

Browse files
authoredNov 25, 2017
Print error message if archive file can't be found. (#124)
Fixes #122.
1 parent 2cf8544 commit d65c9cb

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed
 

‎build.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use std::process::Command;
77

88
static AFL_SRC_PATH: &str = "afl-2.52b";
99

10-
#[path = "src/dirs.rs"]
11-
mod dirs;
10+
#[path = "src/common.rs"]
11+
mod common;
1212

1313
fn main() {
14-
build_afl(&dirs::afl());
15-
build_afl_llvm_runtime(&dirs::afl_llvm_rt());
14+
build_afl(&common::afl_dir());
15+
build_afl_llvm_runtime();
1616
}
1717

1818
fn build_afl(out_dir: &Path) {
@@ -29,10 +29,7 @@ fn build_afl(out_dir: &Path) {
2929
assert!(status.success());
3030
}
3131

32-
fn build_afl_llvm_runtime(out_dir: &Path) {
33-
let object_file_path = out_dir.join("libafl-llvm-rt.o");
34-
let archive_file_path = out_dir.join("libafl-llvm-rt.a");
35-
32+
fn build_afl_llvm_runtime() {
3633
let status = Command::new("cc")
3734
.current_dir(AFL_SRC_PATH)
3835
.arg("-c")
@@ -41,15 +38,15 @@ fn build_afl_llvm_runtime(out_dir: &Path) {
4138
.arg("-fno-omit-frame-pointer")
4239
.arg("llvm_mode/afl-llvm-rt.o.c")
4340
.arg("-fpermissive")
44-
.args(&[OsStr::new("-o"), object_file_path.as_os_str()])
41+
.args(&[OsStr::new("-o"), common::object_file_path().as_os_str()])
4542
.status()
4643
.expect("could not run 'gcc'");
4744
assert!(status.success());
4845

4946
let status = Command::new("ar")
5047
.arg("r")
51-
.arg(archive_file_path)
52-
.arg(object_file_path)
48+
.arg(common::archive_file_path())
49+
.arg(common::object_file_path())
5350
.status()
5451
.expect("could not run 'ar'");
5552
assert!(status.success());

‎src/bin/cargo-afl.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ use std::env;
77
use std::ffi::OsStr;
88
use std::process::{self, Command};
99

10-
#[path = "../dirs.rs"]
11-
mod dirs;
10+
#[path = "../common.rs"]
11+
mod common;
1212

1313
fn main() {
14+
if !common::archive_file_path().exists() {
15+
let version = common::rustc_version();
16+
eprintln!("AFL LLVM runtime is not built with Rust {}, run `cargo \
17+
install --force afl` to build it.", version);
18+
process::exit(1);
19+
}
20+
1421
let _ = clap_app().get_matches();
1522

1623
let mut args = env::args().skip(2).peekable(); // skip `cargo` and `afl`
@@ -127,7 +134,7 @@ where
127134
I: IntoIterator<Item = S>,
128135
S: AsRef<OsStr>,
129136
{
130-
let cmd_path = dirs::afl().join("bin").join(cmd);
137+
let cmd_path = common::afl_dir().join("bin").join(cmd);
131138
let status = Command::new(cmd_path)
132139
.args(args.into_iter().skip(1)) // skip afl sub-command
133140
.status()
@@ -149,7 +156,7 @@ where
149156
-C panic=abort \
150157
-l afl-llvm-rt \
151158
-L {}",
152-
dirs::afl_llvm_rt().display()
159+
common::afl_llvm_rt_dir().display()
153160
);
154161
let status = Command::new(cargo_path)
155162
.args(args) // skip `cargo` and `afl`

‎src/dirs.rs ‎src/common.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn xdg_dir() -> xdg::BaseDirectories {
1010
xdg::BaseDirectories::with_prefix(prefix).unwrap()
1111
}
1212

13-
fn rustc_version() -> String {
13+
pub fn rustc_version() -> String {
1414
let mut ret = String::from("rustc-");
1515
ret.push_str(&rustc_version::version().unwrap().to_string());
1616
ret
@@ -26,10 +26,19 @@ fn pkg_version() -> String {
2626
ret
2727
}
2828

29-
pub fn afl() -> PathBuf {
29+
pub fn afl_dir() -> PathBuf {
3030
xdg_dir().create_data_directory("afl").unwrap()
3131
}
3232

33-
pub fn afl_llvm_rt() -> PathBuf {
33+
pub fn afl_llvm_rt_dir() -> PathBuf {
3434
xdg_dir().create_data_directory("afl-llvm-rt").unwrap()
3535
}
36+
37+
#[allow(dead_code)]
38+
pub fn object_file_path() -> PathBuf {
39+
afl_llvm_rt_dir().join("libafl-llvm-rt.o")
40+
}
41+
42+
pub fn archive_file_path() -> PathBuf {
43+
afl_llvm_rt_dir().join("libafl-llvm-rt.a")
44+
}

0 commit comments

Comments
 (0)
Please sign in to comment.