Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,27 @@ pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize
///
#[macro_export]
macro_rules! fuzz_target {
(|$bytes:ident| $body:expr) => {
$crate::fuzz_target!(init: (), |$bytes: &[u8]| -> () { $body });
};

(|$bytes:ident: &[u8]| $body:expr) => {
$crate::fuzz_target!(init: (), |$bytes: &[u8]| -> () { $body });
};

(|$bytes:ident: &[u8]| -> $rty:ty $body:block) => {
$crate::fuzz_target!(init: (), |$bytes: &[u8]| -> $rty { $body });
};

(init: $init:expr, |$bytes:ident| $body:expr) => {
$crate::fuzz_target!(init: $init, |$bytes: &[u8]| -> () { $body });
};

(init: $init:expr, |$bytes:ident: &[u8]| $body:expr) => {
$crate::fuzz_target!(init: $init, |$bytes: &[u8]| -> () { $body });
};

(init: $init:expr, |$bytes:ident: &[u8]| -> $rty:ty $body:block) => {
const _: () = {
/// Auto-generated functions
/// LLVMFuzzerInitialize is called once before the fuzzer starts.
Expand Down Expand Up @@ -253,8 +273,8 @@ macro_rules! fuzz_target {
return 0;
}

__libfuzzer_sys_run(bytes);
0
let result = ::libfuzzer_sys::Corpus::from(__libfuzzer_sys_run(bytes));
result.to_libfuzzer_code()
}

// Split out the actual fuzzer into a separate function which is
Expand All @@ -270,20 +290,12 @@ macro_rules! fuzz_target {
// ideally help prevent oss-fuzz from deduplicate fuzz bugs across
// distinct targets accidentally.
#[inline(never)]
fn __libfuzzer_sys_run($bytes: &[u8]) {
fn __libfuzzer_sys_run($bytes: &[u8]) -> $rty {
$body
}
};
};

(|$bytes:ident| $body:expr) => {
$crate::fuzz_target!(|$bytes: &[u8]| $body);
};

(|$data:ident: &[u8]| $body:expr) => {
$crate::fuzz_target!(init: (), |$data| $body);
};

(|$data:ident: $dty:ty| $body:expr) => {
$crate::fuzz_target!(init: (), |$data: $dty| -> () { $body });
};
Expand All @@ -292,14 +304,6 @@ macro_rules! fuzz_target {
$crate::fuzz_target!(init: (), |$data: $dty| -> $rty { $body });
};

(init: $init:expr, |$data:ident: &[u8]| $body:expr) => {
$crate::fuzz_target!(init: $init, |$data| $body);
};

(init: $init:expr, |$bytes:ident| $body:expr) => {
$crate::fuzz_target!(init: $init, |$bytes: &[u8]| $body);
};

(init: $init:expr, |$data:ident: $dty:ty| $body:expr) => {
$crate::fuzz_target!(init: $init, |$data: $dty| -> () { $body });
};
Expand Down