Skip to content

test: fix null pointer issue when DevicePath is null + integration test #859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion uefi-test-runner/src/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use uefi::proto::console::text::Output;
use uefi::proto::device_path::media::FilePath;
use uefi::proto::device_path::{DevicePath, LoadedImageDevicePath};
use uefi::table::boot::{BootServices, LoadImageSource, SearchType};
use uefi::table::boot::{OpenProtocolAttributes, OpenProtocolParams};
use uefi::table::{Boot, SystemTable};
use uefi::{CString16, Identify};

Expand Down Expand Up @@ -85,11 +86,24 @@ fn test_load_image(bt: &BootServices) {
buffer: image_data.as_slice(),
file_path: None,
};
let _ = bt
let loaded_image = bt
.load_image(bt.image_handle(), load_source)
.expect("should load image");

log::debug!("load_image with FromBuffer strategy works");

unsafe {
let _ = bt
.open_protocol::<LoadedImageDevicePath>(
OpenProtocolParams {
handle: loaded_image,
agent: bt.image_handle(),
controller: None,
},
OpenProtocolAttributes::GetProtocol,
)
.expect("should open LoadedImageDevicePath protocol");
}
}
// Variant B: FromDevicePath
{
Expand Down
4 changes: 4 additions & 0 deletions uefi/src/proto/device_path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,12 @@ pub struct DevicePath {

impl ProtocolPointer for DevicePath {
unsafe fn ptr_from_ffi(ptr: *const c_void) -> *const Self {
assert!(!ptr.is_null());
ptr_meta::from_raw_parts(ptr.cast(), Self::size_in_bytes_from_ptr(ptr))
}

unsafe fn mut_ptr_from_ffi(ptr: *mut c_void) -> *mut Self {
assert!(!ptr.is_null());
ptr_meta::from_raw_parts_mut(ptr.cast(), Self::size_in_bytes_from_ptr(ptr))
}
}
Expand Down Expand Up @@ -684,10 +686,12 @@ pub struct LoadedImageDevicePath(DevicePath);

impl ProtocolPointer for LoadedImageDevicePath {
unsafe fn ptr_from_ffi(ptr: *const c_void) -> *const Self {
assert!(!ptr.is_null());
ptr_meta::from_raw_parts(ptr.cast(), DevicePath::size_in_bytes_from_ptr(ptr))
}

unsafe fn mut_ptr_from_ffi(ptr: *mut c_void) -> *mut Self {
assert!(!ptr.is_null());
ptr_meta::from_raw_parts_mut(ptr.cast(), DevicePath::size_in_bytes_from_ptr(ptr))
}
}
Expand Down
2 changes: 2 additions & 0 deletions uefi/src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ where
P: Protocol,
{
unsafe fn ptr_from_ffi(ptr: *const c_void) -> *const Self {
assert!(!ptr.is_null());
ptr.cast::<Self>()
}

unsafe fn mut_ptr_from_ffi(ptr: *mut c_void) -> *mut Self {
assert!(!ptr.is_null());
ptr.cast::<Self>()
}
}
Expand Down