File tree Expand file tree Collapse file tree 4 files changed +45
-4
lines changed Expand file tree Collapse file tree 4 files changed +45
-4
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,10 @@ jobs:
105
105
- name : Run miri tests
106
106
run : RUST_BACKTRACE=1 MIRIFLAGS="-Zmiri-disable-isolation" cargo +nightly miri test
107
107
108
+ # --- test embedding the libafl_libfuzzer_runtime library
109
+ - name : Test Build libafl_libfuzzer with embed
110
+ run : cargo +nightly test --features=embed-runtime --manifest-path libafl_libfuzzer/Cargo.toml
111
+
108
112
ubuntu-check :
109
113
runs-on : ubuntu-22.04
110
114
steps :
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ include = [
14
14
" /Cargo.toml" ,
15
15
" /build.rs" ,
16
16
" /libafl_libfuzzer_runtime" ,
17
- " !/libafl_libfuzzer_runtime/target"
17
+ " !/libafl_libfuzzer_runtime/target" ,
18
18
]
19
19
20
20
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -30,6 +30,10 @@ rustversion = "1.0"
30
30
arbitrary-derive = [" libfuzzer-sys/arbitrary-derive" ]
31
31
# # Enables fuzzer introspection with LibAFL's `introspection` feature
32
32
introspection = []
33
+ # # Embeds the built libafl_libfuzzer_runtime library into the crate with include_bytes! for use
34
+ # # in downstream cases like libafl_cc linking the runtime with:
35
+ # # `-fsanitize=fuzzer-no-link -l:libafl_libfuzzer_runtime.a`
36
+ embed-runtime = []
33
37
34
38
[dependencies ]
35
39
libfuzzer-sys = { version = " 0.4.7" , default-features = false }
@@ -39,6 +43,4 @@ document-features = { version = "0.2" }
39
43
features = [" document-features" ]
40
44
all-features = true
41
45
42
- rustdoc-args = [
43
- " --cfg" , " docsrs" ,
44
- ]
46
+ rustdoc-args = [" --cfg" , " docsrs" ]
Original file line number Diff line number Diff line change @@ -70,6 +70,16 @@ fn main() {
70
70
let mut lib_path = custom_lib_dir. join ( std:: env:: var_os ( "TARGET" ) . unwrap ( ) ) ;
71
71
lib_path. push ( "release" ) ;
72
72
73
+ #[ cfg( all( feature = "embed-runtime" , target_family = "unix" ) ) ]
74
+ {
75
+ // NOTE: lib, .a are added always on unix-like systems as described in:
76
+ // https://gist.github.com/novafacing/1389cbb2f0a362d7eb103e67b4468e2b
77
+ println ! (
78
+ "cargo:rustc-env=LIBAFL_LIBFUZZER_RUNTIME_PATH={}" ,
79
+ lib_path. join( "libafl_libfuzzer_runtime.a" ) . display( )
80
+ ) ;
81
+ }
82
+
73
83
println ! (
74
84
"cargo:rustc-link-search=native={}" ,
75
85
lib_path. to_str( ) . unwrap( )
Original file line number Diff line number Diff line change @@ -90,3 +90,28 @@ extern "C" {
90
90
harness_fn : Option < extern "C" fn ( * const u8 , usize ) -> c_int > ,
91
91
) -> c_int ;
92
92
}
93
+
94
+ #[ cfg( all(
95
+ feature = "embed-runtime" ,
96
+ target_family = "unix" ,
97
+ // Disable when building with clippy, as it will complain about the missing environment
98
+ // variable which is set by the build script, which is not run under clippy.
99
+ not( feature = "cargo-clippy" )
100
+ ) ) ]
101
+ pub const LIBAFL_LIBFUZZER_RUNTIME_LIBRARY : & ' static [ u8 ] =
102
+ include_bytes ! ( env!( "LIBAFL_LIBFUZZER_RUNTIME_PATH" ) ) ;
103
+
104
+ #[ cfg( test) ]
105
+ mod tests {
106
+ #[ cfg( all( feature = "embed-runtime" , not( feature = "cargo-clippy" ) ) ) ]
107
+ #[ test]
108
+ fn test_embed_runtime_sized ( ) {
109
+ use crate :: LIBAFL_LIBFUZZER_RUNTIME_LIBRARY ;
110
+
111
+ assert_ne ! (
112
+ LIBAFL_LIBFUZZER_RUNTIME_LIBRARY . len( ) ,
113
+ 0 ,
114
+ "Runtime library empty"
115
+ ) ;
116
+ }
117
+ }
You can’t perform that action at this time.
0 commit comments