diff --git a/crates/libafl_nyx/build.rs b/crates/libafl_nyx/build.rs index 1762053122..7bc001f81e 100644 --- a/crates/libafl_nyx/build.rs +++ b/crates/libafl_nyx/build.rs @@ -1,10 +1,20 @@ -use std::process::Command; - +use std::{env, path::PathBuf, process::Command}; fn main() { if cfg!(target_os = "linux") && cfg!(target_arch = "x86_64") && !cfg!(doc) { + // Use CARGO_TARGET_DIR if available, otherwise fall back to OUT_DIR's parent directories + let target_dir = if let Ok(target_dir) = env::var("CARGO_TARGET_DIR") { + PathBuf::from(target_dir) + } else { + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); + out_dir + .ancestors() + .nth(3) + .map(std::path::Path::to_path_buf) + .expect("Failed to determine target directory from OUT_DIR") + }; println!("cargo:rerun-if-changed=build.rs"); - // let output = Command::new("./build_nyx_support.sh").output().expect("can't run ./build_nyx_support.sh"); let status = Command::new("./build_nyx_support.sh") + .arg(target_dir) .status() .expect("can't run ./build_nyx_support.sh"); if status.success() { diff --git a/crates/libafl_nyx/build_nyx_support.sh b/crates/libafl_nyx/build_nyx_support.sh index 4ef525e49c..e073ba6530 100755 --- a/crates/libafl_nyx/build_nyx_support.sh +++ b/crates/libafl_nyx/build_nyx_support.sh @@ -1,7 +1,16 @@ #!/bin/bash +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +TARGET_DIR="$1" +mkdir -p "$TARGET_DIR" +cd "$TARGET_DIR" || exit 1 + echo "=================================================" echo " Nyx build script" echo "=================================================" @@ -44,8 +53,8 @@ echo "[*] Checking QEMU-Nyx ..." if [ ! -f "QEMU-Nyx/x86_64-softmmu/qemu-system-x86_64" ]; then cd QEMU-Nyx/ || return # We need to copy our custom `Makefile.libxdc` after `git submodule update`, otherwise we get a git error. - sed -i "s,git submodule update libxdc$,git submodule update libxdc \&\& cp ../Makefile.libxdc ./libxdc/Makefile || exit 1," compile_qemu_nyx.sh - ./compile_qemu_nyx.sh lto || exit 1 + sed -i "s,git submodule update libxdc$,git submodule update libxdc \&\& cp $SCRIPT_DIR/Makefile.libxdc ./libxdc/Makefile || exit 1," compile_qemu_nyx.sh + ./compile_qemu_nyx.sh lto cd .. fi diff --git a/crates/ll_mp/src/lib.rs b/crates/ll_mp/src/lib.rs index fb8898d6c1..59064a29d3 100644 --- a/crates/ll_mp/src/lib.rs +++ b/crates/ll_mp/src/lib.rs @@ -511,10 +511,10 @@ fn msg_offset_from_env(env_name: &str) -> Result, Error> { /// Will set `SO_REUSEPORT` on unix. #[cfg(feature = "std")] fn tcp_bind(port: u16) -> Result { - let listener = TcpListener::bind((_LLMP_BIND_ADDR, port)) - .map_err(|err| { let err_msg = format!("Failed to bind to port {port}: {err}"); - Error::os_error(err, err_msg) - })?; + let listener = TcpListener::bind((_LLMP_BIND_ADDR, port)).map_err(|err| { + let err_msg = format!("Failed to bind to port {port}: {err}"); + Error::os_error(err, err_msg) + })?; #[cfg(unix)] #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] diff --git a/fuzzers/full_system/nyx_libxml2_parallel/setup_libxml2.sh b/fuzzers/full_system/nyx_libxml2_parallel/setup_libxml2.sh index 85e0080e8b..880eb94f7e 100755 --- a/fuzzers/full_system/nyx_libxml2_parallel/setup_libxml2.sh +++ b/fuzzers/full_system/nyx_libxml2_parallel/setup_libxml2.sh @@ -26,7 +26,7 @@ cd ./libxml2/ || exit ./autogen.sh --enable-shared=no || exit make -j || exit cd - || exit -python3 "../../../crates/libafl_nyx/packer/packer/nyx_packer.py" \ +python3 "./target/debug/packer/packer/nyx_packer.py" \ ./libxml2/xmllint \ /tmp/nyx_libxml2 \ afl \ @@ -36,4 +36,4 @@ python3 "../../../crates/libafl_nyx/packer/packer/nyx_packer.py" \ --fast_reload_mode \ --purge || exit -python3 ../../../crates/libafl_nyx/packer/packer/nyx_config_gen.py /tmp/nyx_libxml2/ Kernel || exit +python3 ./target/debug/packer/packer/nyx_config_gen.py /tmp/nyx_libxml2/ Kernel || exit diff --git a/fuzzers/full_system/nyx_libxml2_standalone/setup_libxml2.sh b/fuzzers/full_system/nyx_libxml2_standalone/setup_libxml2.sh index 85e0080e8b..880eb94f7e 100755 --- a/fuzzers/full_system/nyx_libxml2_standalone/setup_libxml2.sh +++ b/fuzzers/full_system/nyx_libxml2_standalone/setup_libxml2.sh @@ -26,7 +26,7 @@ cd ./libxml2/ || exit ./autogen.sh --enable-shared=no || exit make -j || exit cd - || exit -python3 "../../../crates/libafl_nyx/packer/packer/nyx_packer.py" \ +python3 "./target/debug/packer/packer/nyx_packer.py" \ ./libxml2/xmllint \ /tmp/nyx_libxml2 \ afl \ @@ -36,4 +36,4 @@ python3 "../../../crates/libafl_nyx/packer/packer/nyx_packer.py" \ --fast_reload_mode \ --purge || exit -python3 ../../../crates/libafl_nyx/packer/packer/nyx_config_gen.py /tmp/nyx_libxml2/ Kernel || exit +python3 ./target/debug/packer/packer/nyx_config_gen.py /tmp/nyx_libxml2/ Kernel || exit