Skip to content

Commit 03f950d

Browse files
committed
Update fuzzing test to check for simpleguest in same directory as executable
Signed-off-by: Mark Rossett <[email protected]>
1 parent 137457c commit 03f950d

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/hyperlight_host/fuzz/fuzz_targets/fuzz_target_1.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@ use hyperlight_host::sandbox::uninitialized::GuestBinary;
2121
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
2222
use hyperlight_host::sandbox_state::transition::Noop;
2323
use hyperlight_host::{MultiUseSandbox, UninitializedSandbox};
24-
use hyperlight_testing::simple_guest_as_string;
24+
use hyperlight_testing::simple_guest_for_fuzzing_as_string;
2525
use libfuzzer_sys::fuzz_target;
2626

2727
fuzz_target!(|data: &[u8]| {
28-
let u_sbox = UninitializedSandbox::new(
29-
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
30-
None,
31-
None,
32-
None,
33-
)
34-
.unwrap();
28+
let guest_binary = GuestBinary::FilePath(simple_guest_for_fuzzing_as_string().unwrap());
29+
30+
let u_sbox = UninitializedSandbox::new(guest_binary, None, None, None).unwrap();
3531

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

src/hyperlight_testing/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616

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

2122
use anyhow::{anyhow, Result};
@@ -129,3 +130,28 @@ pub fn c_callback_guest_as_string() -> Result<String> {
129130
.map(|s| s.to_string())
130131
.ok_or_else(|| anyhow!("couldn't convert callback guest PathBuf to string"))
131132
}
133+
134+
/// Get a fully qualified path to a simple guest binary prefering a binary
135+
/// in the same directory as the parent executable. This will be used in
136+
/// fuzzing scenarioes where pre-built binaries will be build and submitted to
137+
/// a fuzzing framework.
138+
pub fn simple_guest_for_fuzzing_as_string() -> Result<String> {
139+
let exe_dir = env::current_exe()
140+
.ok()
141+
.and_then(|path| path.parent().map(|p| p.to_path_buf()));
142+
143+
if exe_dir.is_some() {
144+
if let Some(exe_dir) = exe_dir {
145+
let guest_path = exe_dir.join("simpleguest");
146+
147+
if guest_path.exists() {
148+
return Ok(guest_path
149+
.to_str()
150+
.ok_or(anyhow!("Invalid path string"))?
151+
.to_string());
152+
}
153+
}
154+
}
155+
156+
simple_guest_as_string()
157+
}

0 commit comments

Comments
 (0)