mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Add trivial fuzzer for parser
As described in #61, fuzz testing some parts of this would be ~~fun~~ helpful. So, I started with the most trivial fuzzer I could think of: Put random stuff into File::parse and see what happens. To speed things up, I also did cp src/**/*.rs fuzz/corpus/parser/ in the `crates/libsyntax2/` directory (running the fuzzer once will generate the necessary directories).
This commit is contained in:
parent
df05c5c3e2
commit
a37cd5ad43
3 changed files with 38 additions and 0 deletions
4
crates/libsyntax2/fuzz/.gitignore
vendored
Normal file
4
crates/libsyntax2/fuzz/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
target
|
||||
corpus
|
||||
artifacts
|
22
crates/libsyntax2/fuzz/Cargo.toml
Normal file
22
crates/libsyntax2/fuzz/Cargo.toml
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
[package]
|
||||
name = "libsyntax2-fuzz"
|
||||
version = "0.0.1"
|
||||
authors = ["Automatically generated"]
|
||||
publish = false
|
||||
|
||||
[package.metadata]
|
||||
cargo-fuzz = true
|
||||
|
||||
[dependencies.libsyntax2]
|
||||
path = ".."
|
||||
[dependencies.libfuzzer-sys]
|
||||
git = "https://github.com/rust-fuzz/libfuzzer-sys.git"
|
||||
|
||||
# Prevent this from interfering with workspaces
|
||||
[workspace]
|
||||
members = ["."]
|
||||
|
||||
[[bin]]
|
||||
name = "parser"
|
||||
path = "fuzz_targets/parser.rs"
|
12
crates/libsyntax2/fuzz/fuzz_targets/parser.rs
Normal file
12
crates/libsyntax2/fuzz/fuzz_targets/parser.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
#![no_main]
|
||||
#[macro_use] extern crate libfuzzer_sys;
|
||||
extern crate libsyntax2;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if let Ok(text) = std::str::from_utf8(data) {
|
||||
let x = libsyntax2::File::parse(text);
|
||||
let _ = x.ast();
|
||||
let _ = x.syntax();
|
||||
let _ = x.errors();
|
||||
}
|
||||
});
|
Loading…
Reference in a new issue