Add fuzz target for fallback TokenStream parser

This commit is contained in:
David Tolnay 2022-09-28 13:18:09 -07:00
parent 164a5fdee6
commit 4a8ad4d901
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 36 additions and 0 deletions

3
fuzz/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
artifacts/
corpus/
target/

21
fuzz/Cargo.toml Normal file
View File

@ -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]

View File

@ -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>();
}
}
});