Skip to content

Commit

Permalink
Update fuzzing test to check for simpleguest in same directory as exe…
Browse files Browse the repository at this point in the history
…cutable

Signed-off-by: Mark Rossett <marosset@microsoft.com>
  • Loading branch information
marosset committed Mar 4, 2025
1 parent 137457c commit 03f950d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/hyperlight_host/fuzz/fuzz_targets/fuzz_target_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@ use hyperlight_host::sandbox::uninitialized::GuestBinary;
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
use hyperlight_host::sandbox_state::transition::Noop;
use hyperlight_host::{MultiUseSandbox, UninitializedSandbox};
use hyperlight_testing::simple_guest_as_string;
use hyperlight_testing::simple_guest_for_fuzzing_as_string;
use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
let u_sbox = UninitializedSandbox::new(
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
None,
None,
None,
)
.unwrap();
let guest_binary = GuestBinary::FilePath(simple_guest_for_fuzzing_as_string().unwrap());

let u_sbox = UninitializedSandbox::new(guest_binary, None, None, None).unwrap();

let mu_sbox: MultiUseSandbox = u_sbox.evolve(Noop::default()).unwrap();

Expand Down
26 changes: 26 additions & 0 deletions src/hyperlight_testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

// This crate contains testing utilities which need to be shared across multiple
// crates in this project.
use std::env;
use std::path::PathBuf;

use anyhow::{anyhow, Result};
Expand Down Expand Up @@ -129,3 +130,28 @@ pub fn c_callback_guest_as_string() -> Result<String> {
.map(|s| s.to_string())
.ok_or_else(|| anyhow!("couldn't convert callback guest PathBuf to string"))
}

/// Get a fully qualified path to a simple guest binary prefering a binary
/// in the same directory as the parent executable. This will be used in
/// fuzzing scenarioes where pre-built binaries will be build and submitted to
/// a fuzzing framework.
pub fn simple_guest_for_fuzzing_as_string() -> Result<String> {
let exe_dir = env::current_exe()
.ok()
.and_then(|path| path.parent().map(|p| p.to_path_buf()));

if exe_dir.is_some() {
if let Some(exe_dir) = exe_dir {
let guest_path = exe_dir.join("simpleguest");

if guest_path.exists() {
return Ok(guest_path
.to_str()
.ok_or(anyhow!("Invalid path string"))?
.to_string());
}
}
}

simple_guest_as_string()
}

0 comments on commit 03f950d

Please sign in to comment.