Skip to content

Commit c3e6f73

Browse files
Check table version before calling UEFI 2.0+ functions
The create_event_ex function (in boot services) and query_variable_info (in runtime services) were added to their respective tables in UEFI 2.0. In earlier versions these functions can't be called, so check the table revision before using these function pointers.
1 parent f637bc5 commit c3e6f73

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/table/boot.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! UEFI services available during boot.
22
3-
use super::Header;
3+
use super::{Header, Revision};
44
use crate::data_types::Align;
55
use crate::proto::device_path::{DevicePath, FfiDevicePath};
66
#[cfg(feature = "exts")]
@@ -437,6 +437,9 @@ impl BootServices {
437437
/// More than one event of type `EventType::TIMER` may be part of a single event group. However,
438438
/// there is no mechanism for determining which of the timers was signaled.
439439
///
440+
/// This operation is only supported starting with UEFI 2.0; earlier
441+
/// versions will fail with [`Status::UNSUPPORTED`].
442+
///
440443
/// # Safety
441444
///
442445
/// The caller must ensure they are passing a valid `Guid` as `event_group`, if applicable.
@@ -448,6 +451,10 @@ impl BootServices {
448451
notify_ctx: Option<NonNull<c_void>>,
449452
event_group: Option<NonNull<Guid>>,
450453
) -> Result<Event> {
454+
if self.header.revision < Revision::EFI_2_00 {
455+
return Err(Status::UNSUPPORTED.into());
456+
}
457+
451458
let mut event = MaybeUninit::<Event>::uninit();
452459

453460
(self.create_event_ex)(

src/table/runtime.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! UEFI services available at runtime, even after the OS boots.
22
3-
use super::Header;
3+
use super::{Header, Revision};
44
#[cfg(feature = "exts")]
55
use crate::data_types::FromSliceWithNulError;
66
use crate::result::Error;
@@ -248,11 +248,18 @@ impl RuntimeServices {
248248
/// Get information about UEFI variable storage space for the type
249249
/// of variable specified in `attributes`.
250250
///
251+
/// This operation is only supported starting with UEFI 2.0; earlier
252+
/// versions will fail with [`Status::UNSUPPORTED`].
253+
///
251254
/// See [`VariableStorageInfo`] for details of the information returned.
252255
pub fn query_variable_info(
253256
&self,
254257
attributes: VariableAttributes,
255258
) -> Result<VariableStorageInfo> {
259+
if self.header.revision < Revision::EFI_2_00 {
260+
return Err(Status::UNSUPPORTED.into());
261+
}
262+
256263
let mut info = VariableStorageInfo::default();
257264
unsafe {
258265
(self.query_variable_info)(

0 commit comments

Comments
 (0)