6
6
#[ cfg( any( test, all( feature = "lib" , fuzzing_honggfuzz) ) ) ]
7
7
pub mod fuzzer {
8
8
use bolero_engine:: {
9
- driver, input, panic as bolero_panic, Engine , Never , TargetLocation , Test ,
9
+ driver, input, panic as bolero_panic, Engine , Never , ScopedEngine , TargetLocation , Test ,
10
10
} ;
11
11
use std:: { mem:: MaybeUninit , slice} ;
12
12
@@ -39,6 +39,35 @@ pub mod fuzzer {
39
39
}
40
40
}
41
41
42
+ impl ScopedEngine for HonggfuzzEngine {
43
+ type Output = Never ;
44
+
45
+ fn run < F , R > ( self , mut test : F , options : driver:: Options ) -> Self :: Output
46
+ where
47
+ F : FnMut ( ) -> R ,
48
+ R : bolero_engine:: IntoResult ,
49
+ {
50
+ bolero_panic:: set_hook ( ) ;
51
+
52
+ // extend the lifetime of the bytes so it can be stored in local storage
53
+ let driver = bolero_engine:: driver:: bytes:: Driver :: new ( & [ ] [ ..] , & options) ;
54
+ let driver = bolero_engine:: driver:: object:: Object ( driver) ;
55
+ let mut driver = Box :: new ( driver) ;
56
+
57
+ let mut input = HonggfuzzInput :: new ( options) ;
58
+
59
+ loop {
60
+ driver. reset ( input. get_slice ( ) , & input. options ) ;
61
+ let ( drv, result) = bolero_engine:: any:: run ( driver, & mut test) ;
62
+ driver = drv;
63
+
64
+ if result. is_err ( ) {
65
+ std:: process:: abort ( ) ;
66
+ }
67
+ }
68
+ }
69
+ }
70
+
42
71
pub struct HonggfuzzInput {
43
72
buf_ptr : MaybeUninit < * const u8 > ,
44
73
len_ptr : MaybeUninit < usize > ,
@@ -54,11 +83,15 @@ pub mod fuzzer {
54
83
}
55
84
}
56
85
57
- fn test_input ( & mut self ) -> input :: Bytes {
58
- let input = unsafe {
86
+ fn get_slice ( & mut self ) -> & ' static [ u8 ] {
87
+ unsafe {
59
88
HF_ITER ( self . buf_ptr . as_mut_ptr ( ) , self . len_ptr . as_mut_ptr ( ) ) ;
60
89
slice:: from_raw_parts ( self . buf_ptr . assume_init ( ) , self . len_ptr . assume_init ( ) )
61
- } ;
90
+ }
91
+ }
92
+
93
+ fn test_input ( & mut self ) -> input:: Bytes {
94
+ let input = self . get_slice ( ) ;
62
95
input:: Bytes :: new ( input, & self . options )
63
96
}
64
97
}
0 commit comments