-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.rs
77 lines (61 loc) · 1.87 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#[macro_use] extern crate honggfuzz;
#[macro_use] extern crate fuzztest;
fn main() {
loop {
fuzz!(|data: &[u8]| {
fuzz_marker!("beginning");
if data.len() == 0 {
fuzz_marker!("data_len_0");
}
if data.len() != 10 {return}
fuzz_marker!("data_len_10");
if data[0] != b'q' {return}
if data[1] != b'w' {return}
if data[2] != b'e' {return}
if data[3] != b'r' {return}
if data[4] != b't' {return}
if data[5] != b'y' {return}
fuzz_marker!("qwerty");
if data[6] != b'u' {return}
if data[7] != b'i' {return}
if data[8] != b'o' {return}
if data[9] != b'p' {return}
fuzz_marker!("qwertyuiop");
if data.len() == 0 { // impossible
fuzz_marker!("impossible");
}
});
}
}
// TODO: test that the fuzzer is really reading the input corpus
// by inserting a marker at an edge undiscoverable by the fuzzer but
// covered in the input corpus.
#[cfg(test)]
mod tests {
use fuzztest::*;
#[test]
fn fuzzer_can_find_beginning_marker() {
check_target_with_marker("example", "beginning");
}
#[test]
fn fuzzer_can_find_data_len_0_marker() {
check_target_with_marker("example", "data_len_0");
}
#[test]
fn fuzzer_can_find_data_len_10_marker() {
check_target_with_marker("example", "data_len_10");
}
#[test]
fn fuzzer_can_find_qwerty_marker() {
check_target_with_marker("example", "qwerty");
}
#[test]
fn fuzzer_can_find_qwertyuiop_marker() {
check_target_with_marker("example", "qwertyuiop");
}
#[test]
#[should_panic]
fn fuzzer_cant_find_impossible_marker() {
check_target_with_marker("example", "impossible");
}
}