File tree 1 file changed +11
-0
lines changed
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,11 @@ pub fn fuzz<F>(closure: F) where F: Fn(&[u8]) + std::panic::RefUnwindSafe {
98
98
unsafe { std:: ptr:: read_volatile ( & PERSIST_MARKER ) } ; // hack used in https://github.com/bluss/bencher for black_box()
99
99
// unsafe { asm!("" : : "r"(&PERSIST_MARKER)) }; // hack used in nightly's back_box(), requires feature asm
100
100
101
+ // sets panic hook to abort
102
+ std:: panic:: set_hook ( Box :: new ( |_| {
103
+ std:: process:: abort ( ) ;
104
+ } ) ) ;
105
+
101
106
let mut input = vec ! [ ] ;
102
107
103
108
while unsafe { __afl_persistent_loop ( 1000 ) } != 0 {
@@ -107,11 +112,17 @@ pub fn fuzz<F>(closure: F) where F: Fn(&[u8]) + std::panic::RefUnwindSafe {
107
112
return ;
108
113
}
109
114
115
+ // We still catch unwinding panics just in case the fuzzed code modifies
116
+ // the panic hook.
117
+ // If so, the fuzzer will be unable to tell different bugs appart and you will
118
+ // only be able to find one bug at a time before fixing it to then find a new one.
110
119
let did_panic = std:: panic:: catch_unwind ( || {
111
120
closure ( & input) ;
112
121
} ) . is_err ( ) ;
113
122
114
123
if did_panic {
124
+ // hopefully the custom panic hook will be called before and abort the
125
+ // process before the stack frames are unwinded.
115
126
std:: process:: abort ( ) ;
116
127
}
117
128
input. clear ( ) ;
You can’t perform that action at this time.
0 commit comments