From a37cd5ad43f28e2eddab713266517cf06c256ba7 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Sat, 8 Sep 2018 16:55:53 +0200 Subject: 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). --- crates/libsyntax2/fuzz/.gitignore | 4 ++++ crates/libsyntax2/fuzz/Cargo.toml | 22 ++++++++++++++++++++++ crates/libsyntax2/fuzz/fuzz_targets/parser.rs | 12 ++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 crates/libsyntax2/fuzz/.gitignore create mode 100644 crates/libsyntax2/fuzz/Cargo.toml create mode 100644 crates/libsyntax2/fuzz/fuzz_targets/parser.rs (limited to 'crates/libsyntax2/fuzz') diff --git a/crates/libsyntax2/fuzz/.gitignore b/crates/libsyntax2/fuzz/.gitignore new file mode 100644 index 000000000..572e03bdf --- /dev/null +++ b/crates/libsyntax2/fuzz/.gitignore @@ -0,0 +1,4 @@ + +target +corpus +artifacts diff --git a/crates/libsyntax2/fuzz/Cargo.toml b/crates/libsyntax2/fuzz/Cargo.toml new file mode 100644 index 000000000..916cd5b6f --- /dev/null +++ b/crates/libsyntax2/fuzz/Cargo.toml @@ -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" diff --git a/crates/libsyntax2/fuzz/fuzz_targets/parser.rs b/crates/libsyntax2/fuzz/fuzz_targets/parser.rs new file mode 100644 index 000000000..f941855e8 --- /dev/null +++ b/crates/libsyntax2/fuzz/fuzz_targets/parser.rs @@ -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(); + } +}); -- cgit v1.2.3