Skip to content

Commit 351e3c7

Browse files
authored
Merge branch 'master' into master
2 parents bbab93a + ff32cf5 commit 351e3c7

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ edition = "2018"
1313
members = ["."]
1414

1515
[dependencies]
16-
arbitrary = "0.1"
16+
arbitrary = "0.2"
1717

1818
[build-dependencies]
1919
cc = "1.0"

example_arbitrary/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ members = ["."]
99

1010
[dependencies]
1111
libfuzzer-sys = { path = ".." }
12-
arbitrary = "0.1"
12+
arbitrary = "0.2"

src/lib.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1+
pub use arbitrary;
2+
13
extern "C" {
24
#![allow(improper_ctypes)] // we do not actually cross the FFI bound here
35

46
fn rust_fuzzer_test_input(input: &[u8]);
57
}
68

7-
#[export_name="LLVMFuzzerTestOneInput"]
9+
#[export_name = "LLVMFuzzerTestOneInput"]
810
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 {
1012
let data_slice = ::std::slice::from_raw_parts(data, size);
1113
rust_fuzzer_test_input(data_slice);
12-
})
13-
.err().map(|_|
14+
});
15+
if test_input.err().is_some() {
1416
// hopefully the custom panic hook will be called before and abort the
1517
// process before the stack frames are unwinded.
16-
::std::process::abort()
17-
);
18+
::std::process::abort();
19+
}
1820
0
1921
}
2022

21-
#[export_name="LLVMFuzzerInitialize"]
23+
#[export_name = "LLVMFuzzerInitialize"]
2224
pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize {
2325
// Registers a panic hook that aborts the process before unwinding.
2426
// 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
3032
// https://github.com/rust-lang/cargo/issues/5423 is fixed.
3133
let default_hook = ::std::panic::take_hook();
3234
::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();
3537
}));
3638
0
3739
}
@@ -40,7 +42,7 @@ pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize
4042
macro_rules! fuzz_target {
4143
(|$bytes:ident| $body:block) => {
4244
#[no_mangle]
43-
pub extern fn rust_fuzzer_test_input($bytes: &[u8]) {
45+
pub extern "C" fn rust_fuzzer_test_input($bytes: &[u8]) {
4446
$body
4547
}
4648
};
@@ -49,8 +51,8 @@ macro_rules! fuzz_target {
4951
};
5052
(|$data:ident: $dty: ty| $body:block) => {
5153
#[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};
5456

5557
let mut buf = match RingBuffer::new(bytes, bytes.len()) {
5658
Ok(b) => b,

0 commit comments

Comments
 (0)