Skip to content

Commit

Permalink
Merge pull request #352 from dtolnay/fuzz
Browse files Browse the repository at this point in the history
Add fuzz target for fallback TokenStream parser
  • Loading branch information
dtolnay authored Sep 28, 2022
2 parents 164a5fd + 4f0ade5 commit 4784921
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ jobs:
target: wasm32-unknown-unknown
- run: cargo test --target wasm32-unknown-unknown --no-run

fuzz:
name: Fuzz
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-fuzz
- run: cargo fuzz build -O

clippy:
name: Clippy
runs-on: ubuntu-latest
Expand Down Expand Up @@ -99,3 +108,4 @@ jobs:
- uses: actions/checkout@v3
- uses: dtolnay/install@cargo-outdated
- run: cargo outdated --workspace --exit-code 1
- run: cargo outdated --manifest-path fuzz/Cargo.toml --exit-code 1
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 4784921

Please sign in to comment.