Skip to content

Commit dd59a2d

Browse files
committed
Add info on how to use the fuzz_target macro
1 parent e3d09e7 commit dd59a2d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ fuzzer-sys = { path = "../libfuzzer-sys" } # or something
1818
1919
$ cat src/main.rs
2020
#![no_main]
21+
#[macro_use]
2122
extern crate fuzzer_sys;
2223
23-
#[export_name="rust_fuzzer_test_input"]
24-
pub extern fn go(data: &[u8]) {
25-
// code to be fuzzed goes here
26-
}
24+
fuzz_target!(|data| {
25+
// code to fuzz goes here
26+
});
2727
2828
$ cargo rustc -- -C passes='sancov' -C llvm-args='-sanitizer-coverage-level=3' -Z sanitizer=address -Cpanic=abort
2929
$ ./target/debug/fuzzed # runs fuzzing
3030
```
3131

32-
Nice wrappers incoming soon
32+
For a nice wrapper see [cargo-fuzz].
33+
34+
[cargo-fuzz]: https://github.com/rust-fuzz/cargo-fuzz

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn test_input_wrap(data: *const u8, size: usize) -> i32 {
1616
}
1717

1818
#[macro_export]
19-
macro_rules! fuzzer_target {
19+
macro_rules! fuzz_target {
2020
(|$bytes:ident| $body:block) => {
2121
#[no_mangle]
2222
pub extern fn rust_fuzzer_test_input($bytes: &[u8]) {

0 commit comments

Comments
 (0)