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