File tree Expand file tree Collapse file tree 2 files changed +30
-8
lines changed
hyperlight_host/fuzz/fuzz_targets Expand file tree Collapse file tree 2 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -21,17 +21,13 @@ use hyperlight_host::sandbox::uninitialized::GuestBinary;
2121use hyperlight_host:: sandbox_state:: sandbox:: EvolvableSandbox ;
2222use hyperlight_host:: sandbox_state:: transition:: Noop ;
2323use hyperlight_host:: { MultiUseSandbox , UninitializedSandbox } ;
24- use hyperlight_testing:: simple_guest_as_string ;
24+ use hyperlight_testing:: simple_guest_for_fuzzing_as_string ;
2525use libfuzzer_sys:: fuzz_target;
2626
2727fuzz_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
Original file line number Diff line number Diff 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;
1920use std:: path:: PathBuf ;
2021
2122use 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+ }
You can’t perform that action at this time.
0 commit comments