Skip to content

Commit

Permalink
Add fuzz target for fallback TokenStream parser
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 28, 2022
1 parent 164a5fd commit 4a8ad4d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifacts/
corpus/
target/
21 changes: 21 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "proc-macro2-fuzz"
version = "0.0.0"
authors = ["David Tolnay <dtolnay@gmail.com>"]
edition = "2021"
publish = false

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
proc-macro2 = { path = ".." }

[[bin]]
name = "parse_token_stream"
path = "fuzz_targets/parse_token_stream.rs"
test = false
doc = false

[workspace]
12 changes: 12 additions & 0 deletions fuzz/fuzz_targets/parse_token_stream.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use std::str;

fuzz_target!(|bytes: &[u8]| {
if bytes.len() < 200 {
if let Ok(string) = str::from_utf8(bytes) {
_ = string.parse::<proc_macro2::TokenStream>();
}
}
});

0 comments on commit 4a8ad4d

Please sign in to comment.