Update the fuzzing harness for API changes.

This commit is contained in:
Dan Gohman
2018-07-20 16:18:52 -07:00
parent dd3a9dab6e
commit 1413a58544
3 changed files with 19 additions and 10 deletions

View File

@@ -14,6 +14,7 @@ cranelift-codegen = "0.16.1"
cranelift-wasm = "0.16.1" cranelift-wasm = "0.16.1"
cranelift-native = "0.16.1" cranelift-native = "0.16.1"
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" } libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" }
wasmparser = { version = "0.17.2", default-features = false }
# Prevent this from interfering with workspaces # Prevent this from interfering with workspaces
[workspace] [workspace]

View File

@@ -2,26 +2,34 @@
#[macro_use] #[macro_use]
extern crate libfuzzer_sys; extern crate libfuzzer_sys;
extern crate cranelift; extern crate cranelift_codegen;
extern crate cranelift_wasm; extern crate cranelift_wasm;
extern crate cranelift_native; extern crate cranelift_native;
extern crate wasmtime_runtime; extern crate wasmtime_runtime;
extern crate wasmtime_execute; extern crate wasmtime_execute;
extern crate wasmparser;
use cranelift::settings; use cranelift_codegen::settings;
use cranelift_wasm::translate_module; use cranelift_wasm::translate_module;
use wasmtime_runtime::{ModuleEnvironment, Module};
use wasmparser::{validate};
fuzz_target!(|data: &[u8]| { fuzz_target!(|data: &[u8]| {
if !validate(data, None) {
return;
}
let (flag_builder, isa_builder) = cranelift_native::builders().unwrap_or_else(|_| { let (flag_builder, isa_builder) = cranelift_native::builders().unwrap_or_else(|_| {
panic!("host machine is not a supported target"); panic!("host machine is not a supported target");
}); });
let isa = isa_builder.finish(settings::Flags::new(&flag_builder)); let isa = isa_builder.finish(settings::Flags::new(flag_builder));
let mut runtime = wasmtime_runtime::Runtime::with_flags(isa.flags().clone()); let mut module = Module::new();
let translation = match translate_module(&data, &mut runtime) { let mut runtime = ModuleEnvironment::new(&*isa, &mut module);
Ok(x) => x, match translate_module(&data, &mut runtime) {
Ok(()) => (),
Err(_) => return, Err(_) => return,
}; };
let _exec = match wasmtime_execute::compile_module(&translation, &*isa, &runtime) { let translation = runtime.finish_translation();
let _exec = match wasmtime_execute::compile_module(&*isa, &translation) {
Ok(x) => x, Ok(x) => x,
Err(_) => return, Err(_) => return,
}; };

View File

@@ -75,10 +75,10 @@ if rustup toolchain list | grep -q nightly; then
cargo +nightly install cargo-fuzz cargo +nightly install cargo-fuzz
fi fi
fuzz_module="ffaefab69523eb11935a9b420d58826c8ea65c4c" fuzz_module="8f0d725b20dcea52335cf521a5bb083833a5241f"
ASAN_OPTIONS=detect_leaks=0 \ ASAN_OPTIONS=detect_leaks=0 \
cargo +nightly fuzz run fuzz_translate_module \ cargo +nightly fuzz run compile \
"$topdir/fuzz/corpus/fuzz_translate_module/$fuzz_module" "$topdir/fuzz/corpus/compile/$fuzz_module"
else else
echo "nightly toolchain not found, skipping fuzz target integration test" echo "nightly toolchain not found, skipping fuzz target integration test"
fi fi