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;
21
21
use hyperlight_host:: sandbox_state:: sandbox:: EvolvableSandbox ;
22
22
use hyperlight_host:: sandbox_state:: transition:: Noop ;
23
23
use hyperlight_host:: { MultiUseSandbox , UninitializedSandbox } ;
24
- use hyperlight_testing:: simple_guest_as_string ;
24
+ use hyperlight_testing:: simple_guest_for_fuzzing_as_string ;
25
25
use libfuzzer_sys:: fuzz_target;
26
26
27
27
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( ) ;
35
31
36
32
let mu_sbox: MultiUseSandbox = u_sbox. evolve( Noop :: default ( ) ) . unwrap( ) ;
37
33
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ limitations under the License.
16
16
17
17
// This crate contains testing utilities which need to be shared across multiple
18
18
// crates in this project.
19
+ use std:: env;
19
20
use std:: path:: PathBuf ;
20
21
21
22
use anyhow:: { anyhow, Result } ;
@@ -129,3 +130,28 @@ pub fn c_callback_guest_as_string() -> Result<String> {
129
130
. map ( |s| s. to_string ( ) )
130
131
. ok_or_else ( || anyhow ! ( "couldn't convert callback guest PathBuf to string" ) )
131
132
}
133
+
134
+ /// Get a fully qualified path to a simple guest binary preferring a binary
135
+ /// in the same directory as the parent executable. This will be used in
136
+ /// fuzzing scenarios 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