Skip to content

Commit 5e4752d

Browse files
uefi: Check for null pointer in config_table
`slice::from_raw_parts` requires a valid pointer even if the slice length is zero, so avoid calling it if the configuration table pointer is null.
1 parent df3e5a5 commit 5e4752d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

uefi/src/table/system.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ impl<View: SystemTableView> SystemTable<View> {
7777
#[allow(clippy::missing_const_for_fn)] // Required until we bump the MSRV.
7878
#[must_use]
7979
pub fn config_table(&self) -> &[cfg::ConfigTableEntry] {
80-
unsafe { slice::from_raw_parts((*self.table).cfg_table, (*self.table).nr_cfg) }
80+
unsafe {
81+
let table = &*self.table;
82+
table
83+
.cfg_table
84+
.as_ref()
85+
.map(|ptr| slice::from_raw_parts(ptr, table.nr_cfg))
86+
.unwrap_or(&[])
87+
}
8188
}
8289

8390
/// Creates a new `SystemTable<View>` from a raw address. The address might

0 commit comments

Comments
 (0)