Skip to content

Commit a835998

Browse files
committed
Update to the new arbitrary crate
Since it isn't released yet, we depend on the git version.
1 parent e424378 commit a835998

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ edition = "2018"
1313
members = ["."]
1414

1515
[dependencies]
16-
arbitrary = "0.2"
16+
# arbitrary = "0.3"
17+
arbitrary = { git = "https://github.com/rust-fuzz/arbitrary.git", rev = "8fa099d" }
1718

1819
[build-dependencies]
1920
cc = "1.0"
21+
22+
[features]
23+
arbitrary-derive = ["arbitrary/derive"]

example_arbitrary/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ edition = "2018"
88
members = ["."]
99

1010
[dependencies]
11-
libfuzzer-sys = { path = ".." }
12-
arbitrary = "0.2"
11+
libfuzzer-sys = { path = "..", features = ["arbitrary-derive"] }

example_arbitrary/src/main.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
#![no_main]
22

3-
use libfuzzer_sys::fuzz_target;
3+
use libfuzzer_sys::{arbitrary, fuzz_target};
44

5-
fuzz_target!(|data: u16| {
6-
if data == 0xba7 { // ba[nana]
7-
panic!("success!");
5+
#[derive(arbitrary::Arbitrary, Debug)]
6+
struct Rgb {
7+
r: u8,
8+
g: u8,
9+
b: u8,
10+
}
11+
12+
fuzz_target!(|rgb: Rgb| {
13+
if rgb.r < rgb.g {
14+
if rgb.g < rgb.b {
15+
panic!("success: r < g < b!");
16+
}
817
}
918
});

src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,11 @@ macro_rules! fuzz_target {
129129
(|$data:ident: $dty: ty| $body:block) => {
130130
#[no_mangle]
131131
pub extern "C" fn rust_fuzzer_test_input(bytes: &[u8]) {
132-
use libfuzzer_sys::arbitrary::{Arbitrary, RingBuffer};
132+
use libfuzzer_sys::arbitrary::{Arbitrary, Unstructured};
133133

134-
let mut buf = match RingBuffer::new(bytes, bytes.len()) {
135-
Ok(b) => b,
136-
Err(_) => return,
137-
};
134+
let mut u = Unstructured::new(bytes);
138135

139-
let $data: $dty = match Arbitrary::arbitrary(&mut buf) {
136+
let $data: $dty = match Arbitrary::arbitrary_take_rest(u) {
140137
Ok(d) => d,
141138
Err(_) => return,
142139
};

0 commit comments

Comments
 (0)