From 5a26bf829935bc9697c7971115ef9779761c4c8b Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 26 Jul 2023 01:01:53 +0200 Subject: [PATCH] Added fuzzy tests --- hbvm/fuzz/.gitignore | 5 +++++ hbvm/fuzz/Cargo.toml | 27 +++++++++++++++++++++++++++ hbvm/fuzz/fuzz_targets/vm.rs | 29 +++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 hbvm/fuzz/.gitignore create mode 100644 hbvm/fuzz/Cargo.toml create mode 100644 hbvm/fuzz/fuzz_targets/vm.rs diff --git a/hbvm/fuzz/.gitignore b/hbvm/fuzz/.gitignore new file mode 100644 index 00000000..615384a8 --- /dev/null +++ b/hbvm/fuzz/.gitignore @@ -0,0 +1,5 @@ +target +artifacts +corpus +coverage +Cargo.lock \ No newline at end of file diff --git a/hbvm/fuzz/Cargo.toml b/hbvm/fuzz/Cargo.toml new file mode 100644 index 00000000..f6bc6164 --- /dev/null +++ b/hbvm/fuzz/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "hbvm-fuzz" +version = "0.0.0" +publish = false +edition = "2021" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" + +[dependencies.hbvm] +path = ".." + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[profile.release] +debug = 1 + +[[bin]] +name = "vm" +path = "fuzz_targets/vm.rs" +test = false +doc = false diff --git a/hbvm/fuzz/fuzz_targets/vm.rs b/hbvm/fuzz/fuzz_targets/vm.rs new file mode 100644 index 00000000..13719030 --- /dev/null +++ b/hbvm/fuzz/fuzz_targets/vm.rs @@ -0,0 +1,29 @@ +#![no_main] + +use { + hbvm::vm::{ + mem::{HandlePageFault, Memory, MemoryAccessReason, PageSize}, + Vm, + }, + libfuzzer_sys::fuzz_target, +}; + +fuzz_target!(|data: &[u8]| { + if let Ok(mut vm) = Vm::<_, 0>::new_validated(data, TestTrapHandler) { + let _ = vm.run(); + } +}); + +struct TestTrapHandler; +impl HandlePageFault for TestTrapHandler { + fn page_fault( + &mut self, + _: MemoryAccessReason, + _: &mut Memory, + _: u64, + _: PageSize, + _: *mut u8, + ) -> bool { + false + } +}