diff --git a/cargo-afl/src/common.rs b/cargo-afl/src/common.rs index bbb61f677..7ab7f1c6f 100644 --- a/cargo-afl/src/common.rs +++ b/cargo-afl/src/common.rs @@ -8,7 +8,7 @@ fn xdg_dir() -> xdg::BaseDirectories { xdg::BaseDirectories::with_prefix(prefix).unwrap() } -fn data_dir(base: Option<&Path>, dir_name: &str) -> PathBuf { +fn data_dir(dir_name: &str) -> PathBuf { // For docs.rs builds, use OUT_DIR. // For other cases, use a XDG data directory. // It is necessary to use OUT_DIR for docs.rs builds, @@ -16,13 +16,8 @@ fn data_dir(base: Option<&Path>, dir_name: &str) -> PathBuf { // The Cargo documentation recommends that build scripts // place their generated files at OUT_DIR too, but we // don't change that for now for normal builds. - if let Some(base) = base { - let path = base.join(dir_name); - std::fs::create_dir_all(&path).unwrap(); - path - } else { - xdg_dir().create_data_directory(dir_name).unwrap() - } + // smoelius: AFL++ is no longer built on docs.rs. + xdg_dir().create_data_directory(dir_name).unwrap() } const SHORT_COMMIT_HASH_LEN: usize = 7; @@ -51,24 +46,24 @@ fn pkg_version() -> String { #[allow(dead_code)] #[must_use] -pub fn afl_dir(base: Option<&Path>) -> PathBuf { - data_dir(base, "afl") +pub fn afl_dir() -> PathBuf { + data_dir("afl") } #[allow(dead_code)] #[must_use] -pub fn afl_llvm_dir(base: Option<&Path>) -> PathBuf { - data_dir(base, "afl-llvm") +pub fn afl_llvm_dir() -> PathBuf { + data_dir("afl-llvm") } #[allow(dead_code)] #[must_use] -pub fn object_file_path(base: Option<&Path>) -> PathBuf { - afl_llvm_dir(base).join("libafl-llvm-rt.o") +pub fn object_file_path() -> PathBuf { + afl_llvm_dir().join("libafl-llvm-rt.o") } #[allow(dead_code)] #[must_use] -pub fn archive_file_path(base: Option<&Path>) -> PathBuf { - afl_llvm_dir(base).join("libafl-llvm-rt.a") +pub fn archive_file_path() -> PathBuf { + afl_llvm_dir().join("libafl-llvm-rt.a") } diff --git a/cargo-afl/src/config.rs b/cargo-afl/src/config.rs index 2f483b487..89caeaec3 100644 --- a/cargo-afl/src/config.rs +++ b/cargo-afl/src/config.rs @@ -34,7 +34,7 @@ pub struct Args { } pub fn config(args: &Args) { - if !args.force && common::archive_file_path(None).exists() { + if !args.force && common::archive_file_path().exists() { let version = common::afl_rustc_version(); eprintln!( "AFL LLVM runtime was already built for Rust {version}; run `cargo \ @@ -68,20 +68,20 @@ pub fn config(args: &Args) { let work_dir = tempdir.path(); - build_afl(args, work_dir, None); - build_afl_llvm_runtime(args, work_dir, None); + build_afl(args, work_dir); + build_afl_llvm_runtime(args, work_dir); if args.plugins { - copy_afl_llvm_plugins(args, work_dir, None); + copy_afl_llvm_plugins(args, work_dir); } eprintln!( "Artifacts written to {}", - common::afl_dir(None).parent().unwrap().display() + common::afl_dir().parent().unwrap().display() ); } -fn build_afl(args: &Args, work_dir: &Path, base: Option<&Path>) { +fn build_afl(args: &Args, work_dir: &Path) { // if you had already installed cargo-afl previously you **must** clean AFL++ // smoelius: AFL++ is now copied to a temporary directory before being built. So `make clean` // is no longer necessary. @@ -91,7 +91,7 @@ fn build_afl(args: &Args, work_dir: &Path, base: Option<&Path>) { .arg("install") // skip the checks for the legacy x86 afl-gcc compiler .env("AFL_NO_X86", "1") - .env("DESTDIR", common::afl_dir(base)) + .env("DESTDIR", common::afl_dir()) .env("PREFIX", "") .env_remove("DEBUG"); @@ -113,18 +113,18 @@ fn build_afl(args: &Args, work_dir: &Path, base: Option<&Path>) { assert!(status.success()); } -fn build_afl_llvm_runtime(args: &Args, work_dir: &Path, base: Option<&Path>) { +fn build_afl_llvm_runtime(args: &Args, work_dir: &Path) { std::fs::copy( work_dir.join("afl-compiler-rt.o"), - common::object_file_path(base), + common::object_file_path(), ) .expect("Couldn't copy object file"); let mut command = Command::new(AR_CMD); command .arg("r") - .arg(common::archive_file_path(base)) - .arg(common::object_file_path(base)); + .arg(common::archive_file_path()) + .arg(common::object_file_path()); if !args.verbose { command.stdout(Stdio::null()); @@ -135,7 +135,7 @@ fn build_afl_llvm_runtime(args: &Args, work_dir: &Path, base: Option<&Path>) { assert!(status.success()); } -fn copy_afl_llvm_plugins(_args: &Args, work_dir: &Path, base: Option<&Path>) { +fn copy_afl_llvm_plugins(_args: &Args, work_dir: &Path) { // Iterate over the files in the directory. for result in work_dir.read_dir().unwrap() { let entry = result.unwrap(); @@ -146,7 +146,7 @@ fn copy_afl_llvm_plugins(_args: &Args, work_dir: &Path, base: Option<&Path>) { // Attempt to copy the shared object file. std::fs::copy( work_dir.join(&file_name), - common::afl_llvm_dir(base).join(&file_name), + common::afl_llvm_dir().join(&file_name), ) .unwrap_or_else(|error| { panic!("Couldn't copy shared object file {file_name:?}: {error}") diff --git a/cargo-afl/src/main.rs b/cargo-afl/src/main.rs index 2f12033a4..23ae16e51 100644 --- a/cargo-afl/src/main.rs +++ b/cargo-afl/src/main.rs @@ -123,7 +123,7 @@ fn main() { }; if !matches!(afl_args.subcmd, Some(AflSubcommand::Config(..))) - && !common::archive_file_path(None).exists() + && !common::archive_file_path().exists() { let version = common::afl_rustc_version(); eprintln!( @@ -182,7 +182,7 @@ where S: AsRef, { let no_sudo = env::var("NO_SUDO").is_ok(); - let cmd_path = common::afl_dir(None).join("bin").join(tool); + let cmd_path = common::afl_dir().join("bin").join(tool); let mut cmd = if !no_sudo && tool == "afl-system-config" { let mut cmd = Command::new("sudo"); cmd.args([OsStr::new("--reset-timestamp"), cmd_path.as_os_str()]); @@ -238,7 +238,7 @@ where // `-C codegen-units=1` is needed to work around link errors // https://github.com/rust-fuzz/afl.rs/pull/193#issuecomment-933550430 - let binding = common::afl_llvm_dir(None); + let binding = common::afl_llvm_dir(); let p = binding.display(); let mut rustflags = format!( @@ -304,7 +304,7 @@ where rustflags.push_str(&format!( "-l afl-llvm-rt \ -L {} ", - common::afl_llvm_dir(None).display() + common::afl_llvm_dir().display() )); // add user provided flags @@ -332,7 +332,7 @@ fn is_nightly() -> bool { } fn plugins_available() -> bool { - let afl_llvm_dir = common::afl_llvm_dir(None); + let afl_llvm_dir = common::afl_llvm_dir(); for result in afl_llvm_dir.read_dir().unwrap() { let entry = result.unwrap(); let file_name = entry.file_name();