diff --git a/cargo-afl/src/common.rs b/cargo-afl/src/common.rs index 1168c7081..f57aa3819 100644 --- a/cargo-afl/src/common.rs +++ b/cargo-afl/src/common.rs @@ -9,7 +9,7 @@ fn xdg_dir(toolchain: Option<&str>) -> xdg::BaseDirectories { xdg::BaseDirectories::with_prefix(prefix).unwrap() } -fn data_dir(base: Option<&Path>, toolchain: Option<&str>, dir_name: &str) -> PathBuf { +fn data_dir(toolchain: Option<&str>, 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, @@ -17,13 +17,8 @@ fn data_dir(base: Option<&Path>, toolchain: Option<&str>, dir_name: &str) -> Pat // 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(toolchain).create_data_directory(dir_name).unwrap() - } + // smoelius: AFL++ is no longer built on docs.rs. + xdg_dir(toolchain).create_data_directory(dir_name).unwrap() } const SHORT_COMMIT_HASH_LEN: usize = 7; @@ -69,24 +64,24 @@ fn pkg_version() -> String { #[allow(dead_code)] #[must_use] -pub fn afl_dir(base: Option<&Path>, toolchain: Option<&str>) -> PathBuf { - data_dir(base, toolchain, "afl") +pub fn afl_dir(toolchain: Option<&str>) -> PathBuf { + data_dir(toolchain, "afl") } #[allow(dead_code)] #[must_use] -pub fn afl_llvm_dir(base: Option<&Path>, toolchain: Option<&str>) -> PathBuf { - data_dir(base, toolchain, "afl-llvm") +pub fn afl_llvm_dir(toolchain: Option<&str>) -> PathBuf { + data_dir(toolchain, "afl-llvm") } #[allow(dead_code)] #[must_use] -pub fn object_file_path(base: Option<&Path>, toolchain: Option<&str>) -> PathBuf { - afl_llvm_dir(base, toolchain).join("libafl-llvm-rt.o") +pub fn object_file_path(toolchain: Option<&str>) -> PathBuf { + afl_llvm_dir(toolchain).join("libafl-llvm-rt.o") } #[allow(dead_code)] #[must_use] -pub fn archive_file_path(base: Option<&Path>, toolchain: Option<&str>) -> PathBuf { - afl_llvm_dir(base, toolchain).join("libafl-llvm-rt.a") +pub fn archive_file_path(toolchain: Option<&str>) -> PathBuf { + afl_llvm_dir(toolchain).join("libafl-llvm-rt.a") } diff --git a/cargo-afl/src/config.rs b/cargo-afl/src/config.rs index 736fd4c28..8e7d4233c 100644 --- a/cargo-afl/src/config.rs +++ b/cargo-afl/src/config.rs @@ -26,7 +26,7 @@ pub struct Args { } pub fn build(args: &Args) { - if !args.force && common::archive_file_path(None, args.toolchain.as_deref()).exists() { + if !args.force && common::archive_file_path(args.toolchain.as_deref()).exists() { let version = common::afl_rustc_version(args.toolchain.as_deref()); eprintln!( "AFL LLVM runtime was already built for Rust {version}; run `cargo \ @@ -64,15 +64,15 @@ pub fn build(args: &Args) { #[cfg(unix)] let _file = sys::lock_path(work_dir).unwrap(); - build_afl(args, work_dir, None, args.toolchain.as_deref()); - build_afl_llvm_runtime(work_dir, None, args.toolchain.as_deref()); + build_afl(args, work_dir, args.toolchain.as_deref()); + build_afl_llvm_runtime(work_dir, args.toolchain.as_deref()); if args.plugins { - copy_afl_llvm_plugins(work_dir, None, args.toolchain.as_deref()); + copy_afl_llvm_plugins(work_dir, args.toolchain.as_deref()); } } -fn build_afl(args: &Args, work_dir: &Path, base: Option<&Path>, toolchain: Option<&str>) { +fn build_afl(args: &Args, work_dir: &Path, toolchain: Option<&str>) { // if you had already installed cargo-afl previously you **must** clean AFL++ let mut command = Command::new("make"); command @@ -80,7 +80,7 @@ fn build_afl(args: &Args, work_dir: &Path, base: Option<&Path>, toolchain: Optio .args(["clean", "install"]) // skip the checks for the legacy x86 afl-gcc compiler .env("AFL_NO_X86", "1") - .env("DESTDIR", common::afl_dir(base, toolchain)) + .env("DESTDIR", common::afl_dir(toolchain)) .env("PREFIX", "") .env_remove("DEBUG"); @@ -99,23 +99,23 @@ fn build_afl(args: &Args, work_dir: &Path, base: Option<&Path>, toolchain: Optio assert!(status.success()); } -fn build_afl_llvm_runtime(work_dir: &Path, base: Option<&Path>, toolchain: Option<&str>) { +fn build_afl_llvm_runtime(work_dir: &Path, toolchain: Option<&str>) { std::fs::copy( work_dir.join("afl-compiler-rt.o"), - common::object_file_path(base, toolchain), + common::object_file_path(toolchain), ) .expect("Couldn't copy object file"); let status = Command::new(AR_CMD) .arg("r") - .arg(common::archive_file_path(base, toolchain)) - .arg(common::object_file_path(base, toolchain)) + .arg(common::archive_file_path(toolchain)) + .arg(common::object_file_path(toolchain)) .status() .expect("could not run 'ar'"); assert!(status.success()); } -fn copy_afl_llvm_plugins(work_dir: &Path, base: Option<&Path>, toolchain: Option<&str>) { +fn copy_afl_llvm_plugins(work_dir: &Path, toolchain: Option<&str>) { // Iterate over the files in the directory. for result in work_dir.read_dir().unwrap() { let entry = result.unwrap(); @@ -126,7 +126,7 @@ fn copy_afl_llvm_plugins(work_dir: &Path, base: Option<&Path>, toolchain: Option // Attempt to copy the shared object file. std::fs::copy( work_dir.join(&file_name), - common::afl_llvm_dir(base, toolchain).join(&file_name), + common::afl_llvm_dir(toolchain).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 5d70784c7..9dedd4d1f 100644 --- a/cargo-afl/src/main.rs +++ b/cargo-afl/src/main.rs @@ -120,7 +120,7 @@ fn main() { }; if !matches!(afl_args.subcmd, Some(AflSubcommand::Config(..))) - && !common::archive_file_path(None, None).exists() + && !common::archive_file_path(None).exists() { let version = common::afl_rustc_version(None); eprintln!( @@ -179,7 +179,7 @@ where S: AsRef, { let no_sudo = env::var("NO_SUDO").is_ok(); - let cmd_path = common::afl_dir(None, None).join("bin").join(tool); + let cmd_path = common::afl_dir(None).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()]); @@ -235,7 +235,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, None); + let binding = common::afl_llvm_dir(None); let p = binding.display(); let mut rustflags = format!( @@ -301,7 +301,7 @@ where rustflags.push_str(&format!( "-l afl-llvm-rt \ -L {} ", - common::afl_llvm_dir(None, None).display() + common::afl_llvm_dir(None).display() )); // add user provided flags @@ -329,7 +329,7 @@ fn is_nightly() -> bool { } fn plugins_available() -> bool { - let afl_llvm_dir = common::afl_llvm_dir(None, None); + let afl_llvm_dir = common::afl_llvm_dir(None); for result in afl_llvm_dir.read_dir().unwrap() { let entry = result.unwrap(); let file_name = entry.file_name();