1
+ pub use arbitrary;
2
+
1
3
extern "C" {
2
4
#![ allow( improper_ctypes) ] // we do not actually cross the FFI bound here
3
5
4
6
fn rust_fuzzer_test_input ( input : & [ u8 ] ) ;
5
7
}
6
8
7
- #[ export_name= "LLVMFuzzerTestOneInput" ]
9
+ #[ export_name = "LLVMFuzzerTestOneInput" ]
8
10
pub fn test_input_wrap ( data : * const u8 , size : usize ) -> i32 {
9
- :: std:: panic:: catch_unwind ( || unsafe {
11
+ let test_input = :: std:: panic:: catch_unwind ( || unsafe {
10
12
let data_slice = :: std:: slice:: from_raw_parts ( data, size) ;
11
13
rust_fuzzer_test_input ( data_slice) ;
12
- } )
13
- . err ( ) . map ( |_|
14
+ } ) ;
15
+ if test_input . err ( ) . is_some ( ) {
14
16
// hopefully the custom panic hook will be called before and abort the
15
17
// process before the stack frames are unwinded.
16
- :: std:: process:: abort ( )
17
- ) ;
18
+ :: std:: process:: abort ( ) ;
19
+ }
18
20
0
19
21
}
20
22
21
- #[ export_name= "LLVMFuzzerInitialize" ]
23
+ #[ export_name = "LLVMFuzzerInitialize" ]
22
24
pub fn initialize ( _argc : * const isize , _argv : * const * const * const u8 ) -> isize {
23
25
// Registers a panic hook that aborts the process before unwinding.
24
26
// It is useful to abort before unwinding so that the fuzzer will then be
@@ -30,8 +32,8 @@ pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize
30
32
// https://github.com/rust-lang/cargo/issues/5423 is fixed.
31
33
let default_hook = :: std:: panic:: take_hook ( ) ;
32
34
:: std:: panic:: set_hook ( Box :: new ( move |panic_info| {
33
- default_hook ( panic_info) ;
34
- :: std:: process:: abort ( ) ;
35
+ default_hook ( panic_info) ;
36
+ :: std:: process:: abort ( ) ;
35
37
} ) ) ;
36
38
0
37
39
}
@@ -40,7 +42,7 @@ pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize
40
42
macro_rules! fuzz_target {
41
43
( |$bytes: ident| $body: block) => {
42
44
#[ no_mangle]
43
- pub extern fn rust_fuzzer_test_input( $bytes: & [ u8 ] ) {
45
+ pub extern "C" fn rust_fuzzer_test_input( $bytes: & [ u8 ] ) {
44
46
$body
45
47
}
46
48
} ;
@@ -49,8 +51,8 @@ macro_rules! fuzz_target {
49
51
} ;
50
52
( |$data: ident: $dty: ty| $body: block) => {
51
53
#[ no_mangle]
52
- pub extern fn rust_fuzzer_test_input( bytes: & [ u8 ] ) {
53
- use arbitrary:: { Arbitrary , RingBuffer } ;
54
+ pub extern "C" fn rust_fuzzer_test_input( bytes: & [ u8 ] ) {
55
+ use libfuzzer_sys :: arbitrary:: { Arbitrary , RingBuffer } ;
54
56
55
57
let mut buf = match RingBuffer :: new( bytes, bytes. len( ) ) {
56
58
Ok ( b) => b,
0 commit comments