Add embed-runtime feature (#1489)
* Add library embedding feature to libafl_libfuzzer * Add comment describing embed-runtime feature and CI test
This commit is contained in:
parent
134fe6a992
commit
256d010981
4
.github/workflows/build_and_test.yml
vendored
4
.github/workflows/build_and_test.yml
vendored
@ -105,6 +105,10 @@ jobs:
|
|||||||
- name: Run miri tests
|
- name: Run miri tests
|
||||||
run: RUST_BACKTRACE=1 MIRIFLAGS="-Zmiri-disable-isolation" cargo +nightly miri test
|
run: RUST_BACKTRACE=1 MIRIFLAGS="-Zmiri-disable-isolation" cargo +nightly miri test
|
||||||
|
|
||||||
|
# --- test embedding the libafl_libfuzzer_runtime library
|
||||||
|
- name: Test Build libafl_libfuzzer with embed
|
||||||
|
run: cargo +nightly test --features=embed-runtime --manifest-path libafl_libfuzzer/Cargo.toml
|
||||||
|
|
||||||
ubuntu-check:
|
ubuntu-check:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
|
@ -14,7 +14,7 @@ include = [
|
|||||||
"/Cargo.toml",
|
"/Cargo.toml",
|
||||||
"/build.rs",
|
"/build.rs",
|
||||||
"/libafl_libfuzzer_runtime",
|
"/libafl_libfuzzer_runtime",
|
||||||
"!/libafl_libfuzzer_runtime/target"
|
"!/libafl_libfuzzer_runtime/target",
|
||||||
]
|
]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
@ -30,6 +30,10 @@ rustversion = "1.0"
|
|||||||
arbitrary-derive = ["libfuzzer-sys/arbitrary-derive"]
|
arbitrary-derive = ["libfuzzer-sys/arbitrary-derive"]
|
||||||
## Enables fuzzer introspection with LibAFL's `introspection` feature
|
## Enables fuzzer introspection with LibAFL's `introspection` feature
|
||||||
introspection = []
|
introspection = []
|
||||||
|
## Embeds the built libafl_libfuzzer_runtime library into the crate with include_bytes! for use
|
||||||
|
## in downstream cases like libafl_cc linking the runtime with:
|
||||||
|
## `-fsanitize=fuzzer-no-link -l:libafl_libfuzzer_runtime.a`
|
||||||
|
embed-runtime = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libfuzzer-sys = { version = "0.4.7", default-features = false }
|
libfuzzer-sys = { version = "0.4.7", default-features = false }
|
||||||
@ -39,6 +43,4 @@ document-features = { version = "0.2" }
|
|||||||
features = ["document-features"]
|
features = ["document-features"]
|
||||||
all-features = true
|
all-features = true
|
||||||
|
|
||||||
rustdoc-args = [
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
"--cfg", "docsrs",
|
|
||||||
]
|
|
||||||
|
@ -70,6 +70,16 @@ fn main() {
|
|||||||
let mut lib_path = custom_lib_dir.join(std::env::var_os("TARGET").unwrap());
|
let mut lib_path = custom_lib_dir.join(std::env::var_os("TARGET").unwrap());
|
||||||
lib_path.push("release");
|
lib_path.push("release");
|
||||||
|
|
||||||
|
#[cfg(all(feature = "embed-runtime", target_family = "unix"))]
|
||||||
|
{
|
||||||
|
// NOTE: lib, .a are added always on unix-like systems as described in:
|
||||||
|
// https://gist.github.com/novafacing/1389cbb2f0a362d7eb103e67b4468e2b
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-env=LIBAFL_LIBFUZZER_RUNTIME_PATH={}",
|
||||||
|
lib_path.join("libafl_libfuzzer_runtime.a").display()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"cargo:rustc-link-search=native={}",
|
"cargo:rustc-link-search=native={}",
|
||||||
lib_path.to_str().unwrap()
|
lib_path.to_str().unwrap()
|
||||||
|
@ -90,3 +90,28 @@ extern "C" {
|
|||||||
harness_fn: Option<extern "C" fn(*const u8, usize) -> c_int>,
|
harness_fn: Option<extern "C" fn(*const u8, usize) -> c_int>,
|
||||||
) -> c_int;
|
) -> c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
feature = "embed-runtime",
|
||||||
|
target_family = "unix",
|
||||||
|
// Disable when building with clippy, as it will complain about the missing environment
|
||||||
|
// variable which is set by the build script, which is not run under clippy.
|
||||||
|
not(feature = "cargo-clippy")
|
||||||
|
))]
|
||||||
|
pub const LIBAFL_LIBFUZZER_RUNTIME_LIBRARY: &'static [u8] =
|
||||||
|
include_bytes!(env!("LIBAFL_LIBFUZZER_RUNTIME_PATH"));
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[cfg(all(feature = "embed-runtime", not(feature = "cargo-clippy")))]
|
||||||
|
#[test]
|
||||||
|
fn test_embed_runtime_sized() {
|
||||||
|
use crate::LIBAFL_LIBFUZZER_RUNTIME_LIBRARY;
|
||||||
|
|
||||||
|
assert_ne!(
|
||||||
|
LIBAFL_LIBFUZZER_RUNTIME_LIBRARY.len(),
|
||||||
|
0,
|
||||||
|
"Runtime library empty"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user