From c39cba4ae0eb8355c42d8679de07e584051c4762 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 5 Oct 2017 18:00:54 -0700 Subject: [PATCH] Start experimenting with cargo fuzz. This isn't very usable yet. --- fuzz/.gitignore | 3 +++ fuzz/Cargo.toml | 34 ++++++++++++++++++++++++++++++++++ fuzz/fuzz_targets/compile.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 fuzz/.gitignore create mode 100644 fuzz/Cargo.toml create mode 100644 fuzz/fuzz_targets/compile.rs diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 0000000000..a0925114d6 --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,3 @@ +target +corpus +artifacts diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 0000000000..7da0a7b943 --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "wasmstandalone_fuzz" +version = "0.0.1" +authors = ["The Cretonne Project Developers"] +publish = false + +[package.metadata] +cargo-fuzz = true + +[dependencies.wasmstandalone_runtime] +path = "../lib/runtime" + +[dependencies.wasmstandalone_execute] +path = "../lib/execute" + +[dependencies.cretonne] +git = "https://github.com/stoklund/cretonne.git" + +[dependencies.cretonne-wasm] +git = "https://github.com/stoklund/cretonne.git" + +[dependencies.cretonne-native] +git = "https://github.com/stoklund/cretonne.git" + +[dependencies.libfuzzer-sys] +git = "https://github.com/rust-fuzz/libfuzzer-sys.git" + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[[bin]] +name = "compile" +path = "fuzz_targets/compile.rs" diff --git a/fuzz/fuzz_targets/compile.rs b/fuzz/fuzz_targets/compile.rs new file mode 100644 index 0000000000..02e538af4e --- /dev/null +++ b/fuzz/fuzz_targets/compile.rs @@ -0,0 +1,28 @@ +#![no_main] + +#[macro_use] +extern crate libfuzzer_sys; +extern crate cretonne; +extern crate cton_wasm; +extern crate cton_native; +extern crate wasmstandalone_runtime; +extern crate wasmstandalone_execute; + +use cretonne::settings; +use cton_wasm::translate_module; + +fuzz_target!(|data: &[u8]| { + let (flag_builder, isa_builder) = cton_native::builders().unwrap_or_else(|_| { + panic!("host machine is not a supported target"); + }); + let isa = isa_builder.finish(settings::Flags::new(&flag_builder)); + let mut runtime = wasmstandalone_runtime::Runtime::with_flags(isa.flags().clone()); + let translation = match translate_module(&data, &mut runtime) { + Ok(x) => x, + Err(_) => return, + }; + let _exec = match wasmstandalone_execute::compile_module(&translation, &*isa, &runtime) { + Ok(x) => x, + Err(_) => return, + }; +});