Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1224 from dtolnay/fuzz
Add fuzz target for TokenBuffer and file parse
- Loading branch information
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
artifacts/ | ||
corpus/ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[package] | ||
name = "syn-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 = "1" | ||
syn = { path = "..", default-features = false, features = ["full", "parsing"] } | ||
|
||
[[bin]] | ||
name = "create_token_buffer" | ||
path = "fuzz_targets/create_token_buffer.rs" | ||
test = false | ||
doc = false | ||
|
||
[[bin]] | ||
name = "parse_file" | ||
path = "fuzz_targets/parse_file.rs" | ||
test = false | ||
doc = false | ||
|
||
[workspace] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use proc_macro2::Span; | ||
use std::str; | ||
use syn::parse::{ParseStream, Parser}; | ||
|
||
fn immediate_fail(_input: ParseStream) -> syn::Result<()> { | ||
Err(syn::Error::new(Span::call_site(), "")) | ||
} | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
if data.len() < 300 { | ||
if let Ok(string) = str::from_utf8(data) { | ||
_ = immediate_fail.parse_str(string); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!(|data: &[u8]| { | ||
if data.len() < 300 { | ||
if let Ok(string) = str::from_utf8(data) { | ||
_ = syn::parse_file(string); | ||
} | ||
} | ||
}); |