@@ -224,7 +224,27 @@ pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize
224
224
///
225
225
#[ macro_export]
226
226
macro_rules! fuzz_target {
227
+ ( |$bytes: ident| $body: expr) => {
228
+ $crate:: fuzz_target!( init: ( ) , |$bytes: & [ u8 ] | -> ( ) { $body } ) ;
229
+ } ;
230
+
231
+ ( |$bytes: ident: & [ u8 ] | $body: expr) => {
232
+ $crate:: fuzz_target!( init: ( ) , |$bytes: & [ u8 ] | -> ( ) { $body } ) ;
233
+ } ;
234
+
235
+ ( |$bytes: ident: & [ u8 ] | -> $rty: ty $body: block) => {
236
+ $crate:: fuzz_target!( init: ( ) , |$bytes: & [ u8 ] | -> $rty { $body } ) ;
237
+ } ;
238
+
227
239
( init: $init: expr, |$bytes: ident| $body: expr) => {
240
+ $crate:: fuzz_target!( init: $init, |$bytes: & [ u8 ] | -> ( ) { $body } ) ;
241
+ } ;
242
+
243
+ ( init: $init: expr, |$bytes: ident: & [ u8 ] | $body: expr) => {
244
+ $crate:: fuzz_target!( init: $init, |$bytes: & [ u8 ] | -> ( ) { $body } ) ;
245
+ } ;
246
+
247
+ ( init: $init: expr, |$bytes: ident: & [ u8 ] | -> $rty: ty $body: block) => {
228
248
const _: ( ) = {
229
249
/// Auto-generated functions
230
250
/// LLVMFuzzerInitialize is called once before the fuzzer starts.
@@ -253,8 +273,8 @@ macro_rules! fuzz_target {
253
273
return 0 ;
254
274
}
255
275
256
- __libfuzzer_sys_run( bytes) ;
257
- 0
276
+ let result = :: libfuzzer_sys :: Corpus :: from ( __libfuzzer_sys_run( bytes) ) ;
277
+ result . to_libfuzzer_code ( )
258
278
}
259
279
260
280
// Split out the actual fuzzer into a separate function which is
@@ -270,20 +290,12 @@ macro_rules! fuzz_target {
270
290
// ideally help prevent oss-fuzz from deduplicate fuzz bugs across
271
291
// distinct targets accidentally.
272
292
#[ inline( never) ]
273
- fn __libfuzzer_sys_run( $bytes: & [ u8 ] ) {
293
+ fn __libfuzzer_sys_run( $bytes: & [ u8 ] ) -> $rty {
274
294
$body
275
295
}
276
296
} ;
277
297
} ;
278
298
279
- ( |$bytes: ident| $body: expr) => {
280
- $crate:: fuzz_target!( |$bytes: & [ u8 ] | $body) ;
281
- } ;
282
-
283
- ( |$data: ident: & [ u8 ] | $body: expr) => {
284
- $crate:: fuzz_target!( init: ( ) , |$data| $body) ;
285
- } ;
286
-
287
299
( |$data: ident: $dty: ty| $body: expr) => {
288
300
$crate:: fuzz_target!( init: ( ) , |$data: $dty| -> ( ) { $body } ) ;
289
301
} ;
@@ -292,14 +304,6 @@ macro_rules! fuzz_target {
292
304
$crate:: fuzz_target!( init: ( ) , |$data: $dty| -> $rty { $body } ) ;
293
305
} ;
294
306
295
- ( init: $init: expr, |$data: ident: & [ u8 ] | $body: expr) => {
296
- $crate:: fuzz_target!( init: $init, |$data| $body) ;
297
- } ;
298
-
299
- ( init: $init: expr, |$bytes: ident| $body: expr) => {
300
- $crate:: fuzz_target!( init: $init, |$bytes: & [ u8 ] | $body) ;
301
- } ;
302
-
303
307
( init: $init: expr, |$data: ident: $dty: ty| $body: expr) => {
304
308
$crate:: fuzz_target!( init: $init, |$data: $dty| -> ( ) { $body } ) ;
305
309
} ;
0 commit comments