diff --git a/pkgs/tools/security/aflplusplus/default.nix b/pkgs/tools/security/aflplusplus/default.nix index 5d4b761df334..3f436d650a3f 100644 --- a/pkgs/tools/security/aflplusplus/default.nix +++ b/pkgs/tools/security/aflplusplus/default.nix @@ -1,8 +1,22 @@ -{ lib, stdenv, stdenvNoCC, fetchFromGitHub, callPackage, makeWrapper -, clang, llvm, gcc, which, libcgroup, python3, perl, gmp -, file, wine ? null -, cmocka -, llvmPackages +{ + lib, + stdenv, + stdenvNoCC, + fetchFromGitHub, + callPackage, + makeWrapper, + clang, + llvm, + gcc, + which, + libcgroup, + python3, + perl, + gmp, + file, + wine ? null, + cmocka, + llvmPackages, }: # wine fuzzing is only known to work for win32 binaries, and using a mixture of @@ -12,28 +26,42 @@ assert (wine != null) -> (stdenv.targetPlatform.system == "i686-linux"); let aflplusplus-qemu = callPackage ./qemu.nix { }; - qemu-exe-name = if stdenv.targetPlatform.system == "x86_64-linux" then "qemu-x86_64" - else if stdenv.targetPlatform.system == "i686-linux" then "qemu-i386" - else throw "aflplusplus: no support for ${stdenv.targetPlatform.system}!"; + qemu-exe-name = + if stdenv.targetPlatform.system == "x86_64-linux" then + "qemu-x86_64" + else if stdenv.targetPlatform.system == "i686-linux" then + "qemu-i386" + else + throw "aflplusplus: no support for ${stdenv.targetPlatform.system}!"; libdislocator = callPackage ./libdislocator.nix { inherit aflplusplus; }; libtokencap = callPackage ./libtokencap.nix { inherit aflplusplus; }; aflplusplus = stdenvNoCC.mkDerivation rec { pname = "aflplusplus"; - version = "4.10c"; + version = "4.20c"; src = fetchFromGitHub { owner = "AFLplusplus"; repo = "AFLplusplus"; - rev = "v${version}"; - sha256 = "sha256-elghcBw2tIttQo7bkMFRCx8iNqxwY0NCz0343wc8hWA="; + rev = "refs/tags/v${version}"; + hash = "sha256-bS4Zxd2CX8m6zxO/izJi7Cj34260mOaU6GWjEj+xEU8="; }; + enableParallelBuilding = true; # Note: libcgroup isn't needed for building, just for the afl-cgroup # script. - nativeBuildInputs = [ makeWrapper which clang gcc ]; - buildInputs = [ llvm python3 gmp llvmPackages.bintools ] - ++ lib.optional (wine != null) python3.pkgs.wrapPython; + nativeBuildInputs = [ + makeWrapper + which + clang + gcc + ]; + buildInputs = [ + llvm + python3 + gmp + llvmPackages.bintools + ] ++ lib.optional (wine != null) python3.pkgs.wrapPython; # Flag is already set by package and causes some compiler warnings. # warning: "_FORTIFY_SOURCE" redefined @@ -48,22 +76,22 @@ let # Prevents afl-gcc picking up any (possibly incorrect) gcc from the path. # Replace LLVM_BINDIR with a non-existing path to give a hard error when it's used. substituteInPlace src/afl-cc.c \ - --replace "CLANGPP_BIN" '"${clang}/bin/clang++"' \ - --replace "CLANG_BIN" '"${clang}/bin/clang"' \ - --replace '"gcc"' '"${gcc}/bin/gcc"' \ - --replace '"g++"' '"${gcc}/bin/g++"' \ - --replace 'getenv("AFL_PATH")' "(getenv(\"AFL_PATH\") ? getenv(\"AFL_PATH\") : \"$out/lib/afl\")" + --replace-fail "CLANGPP_BIN" '"${clang}/bin/clang++"' \ + --replace-fail "CLANG_BIN" '"${clang}/bin/clang"' \ + --replace-fail '"gcc"' '"${gcc}/bin/gcc"' \ + --replace-fail '"g++"' '"${gcc}/bin/g++"' \ + --replace-fail 'getenv("AFL_PATH")' "(getenv(\"AFL_PATH\") ? getenv(\"AFL_PATH\") : \"$out/lib/afl\")" substituteInPlace src/afl-ld-lto.c \ - --replace 'LLVM_BINDIR' '"/nixpkgs-patched-does-not-exist"' + --replace-fail 'LLVM_BINDIR' '"/nixpkgs-patched-does-not-exist"' # Remove the rest of the line sed -i 's|LLVM_BINDIR = .*|LLVM_BINDIR = |' utils/aflpp_driver/GNUmakefile substituteInPlace utils/aflpp_driver/GNUmakefile \ - --replace 'LLVM_BINDIR = ' 'LLVM_BINDIR = ${clang}/bin/' + --replace-fail 'LLVM_BINDIR = ' 'LLVM_BINDIR = ${clang}/bin/' substituteInPlace GNUmakefile.llvm \ - --replace "\$(LLVM_BINDIR)/clang" "${clang}/bin/clang" + --replace-fail "\$(LLVM_BINDIR)/clang" "${clang}/bin/clang" ''; env.NIX_CFLAGS_COMPILE = toString [ @@ -72,9 +100,10 @@ let ]; makeFlags = [ - "PREFIX=$(out)" + "PREFIX=${placeholder "out"}" "USE_BINDIR=0" ]; + buildPhase = '' runHook preBuild @@ -86,67 +115,73 @@ let runHook postBuild ''; - postInstall = '' - # remove afl-clang(++) which are just symlinks to afl-clang-fast - rm $out/bin/afl-clang $out/bin/afl-clang++ + postInstall = + '' + # remove afl-clang(++) which are just symlinks to afl-clang-fast + rm $out/bin/afl-clang $out/bin/afl-clang++ - # the makefile neglects to install unsigaction - cp qemu_mode/unsigaction/unsigaction*.so $out/lib/afl/ + # the makefile neglects to install unsigaction + cp qemu_mode/unsigaction/unsigaction*.so $out/lib/afl/ - # Install the custom QEMU emulator for binary blob fuzzing. - ln -s ${aflplusplus-qemu}/bin/${qemu-exe-name} $out/bin/afl-qemu-trace + # Install the custom QEMU emulator for binary blob fuzzing. + ln -s ${aflplusplus-qemu}/bin/${qemu-exe-name} $out/bin/afl-qemu-trace - # give user a convenient way of accessing libcompconv.so, libdislocator.so, libtokencap.so - cat > $out/bin/get-afl-qemu-libcompcov-so < $out/bin/get-afl-qemu-libcompcov-so <