Skip to content

Commit 0991ba4

Browse files
committed
Check if the DevicePath is valid
1 parent 733855d commit 0991ba4

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/proto/loaded_image.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
data_types::FromSliceWithNulError,
55
proto::{device_path::DevicePath, Protocol},
66
table::boot::MemoryType,
7-
unsafe_guid, CStr16, Char16, Handle, Status,
7+
unsafe_guid, CStr16, Handle, Status,
88
};
99
use core::{ffi::c_void, mem, slice};
1010

@@ -55,21 +55,12 @@ impl LoadedImage {
5555
self.device_handle
5656
}
5757

58-
/// Return a NULL-terminated Path string including directory and file names.
58+
/// Get a reference to the `file_path`.
5959
///
60-
/// `file_path` is a pointer to the file path portion specific to DeviceHandle
61-
/// that the EFI Image was loaded from. It will be empty if the image is loaded
62-
/// from a buffer and the `file_path` is `None`.
63-
///
64-
/// # Safety
65-
///
66-
/// The callers should guarantee the image is loaded from file. If the image
67-
/// is loaded from a buffer, make sure not passing an incorrect `DevicePath`,
68-
/// which may case an undefined behavior.
69-
pub unsafe fn file_path(&self) -> &CStr16 {
70-
// path name follows the DevicePathHeader.
71-
let path_name = self.file_path.offset(1);
72-
CStr16::from_ptr(path_name.cast::<Char16>())
60+
/// Return `None` if the pointer to the file path portion specific to
61+
/// DeviceHandle that the EFI Image was loaded from is null.
62+
pub fn file_path(&self) -> Option<&DevicePath> {
63+
unsafe { self.file_path.as_ref() }
7364
}
7465

7566
/// Get the load options of the image as a [`&CStr16`].

0 commit comments

Comments
 (0)