From 825258939bee841a3715edf6e2a1fb8a95a4d1cc Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 28 Sep 2021 15:54:01 -0700 Subject: [PATCH] Define a fuzz target for the parser --- cranelift/isle/Cargo.lock | 25 +++++++++++++++++++++++ cranelift/isle/Cargo.toml | 6 +++++- cranelift/isle/fuzz/.gitignore | 3 +++ cranelift/isle/fuzz/Cargo.toml | 19 +++++++++++++++++ cranelift/isle/fuzz/fuzz_targets/parse.rs | 9 ++++++++ 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 cranelift/isle/fuzz/.gitignore create mode 100644 cranelift/isle/fuzz/Cargo.toml create mode 100644 cranelift/isle/fuzz/fuzz_targets/parse.rs diff --git a/cranelift/isle/Cargo.lock b/cranelift/isle/Cargo.lock index 08c529adf6..6a0f0849c0 100644 --- a/cranelift/isle/Cargo.lock +++ b/cranelift/isle/Cargo.lock @@ -35,6 +35,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "arbitrary" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "577b08a4acd7b99869f863c50011b01eb73424ccc798ecd996f2e24817adfca7" + [[package]] name = "atty" version = "0.2.14" @@ -148,6 +154,14 @@ dependencies = [ "thiserror", ] +[[package]] +name = "isle-fuzz" +version = "0.0.0" +dependencies = [ + "isle", + "libfuzzer-sys", +] + [[package]] name = "islec" version = "0.1.0" @@ -171,6 +185,17 @@ version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" +[[package]] +name = "libfuzzer-sys" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36a9a84a6e8b55dfefb04235e55edb2b9a2a18488fcae777a6bdaa6f06f1deb3" +dependencies = [ + "arbitrary", + "cc", + "once_cell", +] + [[package]] name = "log" version = "0.4.14" diff --git a/cranelift/isle/Cargo.toml b/cranelift/isle/Cargo.toml index 2f3fcbb680..d1cf4b88ec 100644 --- a/cranelift/isle/Cargo.toml +++ b/cranelift/isle/Cargo.toml @@ -1,2 +1,6 @@ [workspace] -members = [ "isle", "islec" ] +members = [ + "./fuzz", + "./isle", + "./islec", +] diff --git a/cranelift/isle/fuzz/.gitignore b/cranelift/isle/fuzz/.gitignore new file mode 100644 index 0000000000..a0925114d6 --- /dev/null +++ b/cranelift/isle/fuzz/.gitignore @@ -0,0 +1,3 @@ +target +corpus +artifacts diff --git a/cranelift/isle/fuzz/Cargo.toml b/cranelift/isle/fuzz/Cargo.toml new file mode 100644 index 0000000000..dbfb2ddb9a --- /dev/null +++ b/cranelift/isle/fuzz/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "isle-fuzz" +version = "0.0.0" +authors = ["Automatically generated"] +publish = false +edition = "2018" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +isle = { path = "../isle" } +libfuzzer-sys = "0.4" + +[[bin]] +name = "parse" +path = "fuzz_targets/parse.rs" +test = false +doc = false diff --git a/cranelift/isle/fuzz/fuzz_targets/parse.rs b/cranelift/isle/fuzz/fuzz_targets/parse.rs new file mode 100644 index 0000000000..f2a572dbd7 --- /dev/null +++ b/cranelift/isle/fuzz/fuzz_targets/parse.rs @@ -0,0 +1,9 @@ +#![no_main] + +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|s: &str| { + let lexer = isle::lexer::Lexer::from_str(s, "fuzz-input.isle"); + let mut parser = isle::parser::Parser::new(lexer); + let _ = parser.parse_defs(); +});