Skip to content

Commit 05b9ffc

Browse files
Register a custom panic hook calling process::abort()
see the rational at rust-fuzz/honggfuzz-rs@abe2b4c closes #31
1 parent 4594b1f commit 05b9ffc

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,23 @@ pub fn test_input_wrap(data: *const u8, size: usize) -> i32 {
99
::std::panic::catch_unwind(|| unsafe {
1010
let data_slice = ::std::slice::from_raw_parts(data, size);
1111
rust_fuzzer_test_input(data_slice);
12-
}).err().map(|_| ::std::process::abort());
12+
})
13+
.err().map(|_|
14+
// hopefully the custom panic hook will be called before and abort the
15+
// process before the stack frames are unwinded.
16+
::std::process::abort()
17+
);
18+
0
19+
}
20+
21+
#[export_name="LLVMFuzzerInitialize"]
22+
pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize {
23+
// Registers a panic hook that aborts the process before unwinding.
24+
// It is useful to abort before unwinding so that the fuzzer will then be
25+
// able to analyse the process stack frames to tell different bugs appart.
26+
::std::panic::set_hook(Box::new(|_| {
27+
::std::process::abort();
28+
}));
1329
0
1430
}
1531

0 commit comments

Comments
 (0)