File tree Expand file tree Collapse file tree 4 files changed +43
-5
lines changed Expand file tree Collapse file tree 4 files changed +43
-5
lines changed Original file line number Diff line number Diff line change 97
97
- uses : dtolnay/rust-toolchain@nightly
98
98
- uses : dtolnay/install@cargo-fuzz
99
99
- run : cargo fuzz check
100
+ - run : cargo check --no-default-features --features afl
101
+ working-directory : fuzz
102
+
100
103
101
104
clippy :
102
105
name : Clippy
Original file line number Diff line number Diff line change 1
1
artifacts /
2
2
corpus /
3
3
coverage /
4
+ in /
5
+ out /
4
6
target /
Original file line number Diff line number Diff line change @@ -9,10 +9,14 @@ publish = false
9
9
cargo-fuzz = true
10
10
11
11
[dependencies ]
12
- libfuzzer-sys = " 0.4"
12
+ afl = { version = " 0.12" , optional = true }
13
+ libfuzzer-sys = { version = " 0.4" , optional = true }
13
14
proc-macro2 = { path = " .." , default-features = false }
14
15
15
16
[features ]
17
+ default = [" libfuzzer" ]
18
+ afl = [" dep:afl" ]
19
+ libfuzzer = [" dep:libfuzzer-sys" ]
16
20
span-locations = [" proc-macro2/span-locations" ]
17
21
18
22
[[bin ]]
Original file line number Diff line number Diff line change 1
- #![ no_main]
1
+ // libfuzzer:
2
+ //
3
+ // cargo install cargo-fuzz
4
+ // cargo fuzz run parse_token_stream -j $(nproc) -- -max_len=200 -timeout=1
5
+ //
6
+ // afl++:
7
+ //
8
+ // cargo install afl
9
+ // cargo afl build --no-default-features --features afl --release
10
+ // cargo afl fuzz -i in -o out target/release/parse_token_stream
11
+
12
+ #![ cfg_attr( feature = "libfuzzer" , no_main) ]
2
13
3
- use libfuzzer_sys:: fuzz_target;
4
14
use std:: str;
5
15
6
- fuzz_target ! ( |bytes: & [ u8 ] | {
16
+ #[ cfg( not( any(
17
+ all( feature = "libfuzzer" , not( feature = "afl" ) ) ,
18
+ all( not( feature = "libfuzzer" ) , feature = "afl" ) ,
19
+ ) ) ) ]
20
+ fn main ( ) {
21
+ compile_error ! {
22
+ r#"exactly one of feature="libfuzzer" and feature="afl" must be enabled"#
23
+ }
24
+ }
25
+
26
+ #[ cfg( feature = "libfuzzer" ) ]
27
+ libfuzzer_sys:: fuzz_target!( |bytes: & [ u8 ] | { do_fuzz( bytes) } ) ;
28
+
29
+ #[ cfg( feature = "afl" ) ]
30
+ fn main ( ) {
31
+ let hook = true ; // turn panic into crashes
32
+ afl:: fuzz ( hook, do_fuzz) ;
33
+ }
34
+
35
+ fn do_fuzz ( bytes : & [ u8 ] ) {
7
36
if bytes. len ( ) < 200 {
8
37
if let Ok ( string) = str:: from_utf8 ( bytes) {
9
38
_ = string. parse :: < proc_macro2:: TokenStream > ( ) ;
10
39
}
11
40
}
12
- } ) ;
41
+ }
You can’t perform that action at this time.
0 commit comments