Skip to content

Commit 066cb83

Browse files
rcercIsaacWoods
authored andcommitted
acpi: Include header in Dsdt struct to avoid pointer dereference
1 parent 2c3bc2a commit 066cb83

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

acpi/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,17 @@ where
287287
/// Finds and returns the DSDT AML table, if it exists.
288288
pub fn dsdt(&self) -> AcpiResult<AmlTable> {
289289
self.find_table::<fadt::Fadt>().and_then(|fadt| {
290-
struct Dsdt;
290+
#[repr(transparent)]
291+
struct Dsdt {
292+
header: SdtHeader,
293+
}
294+
291295
// Safety: Implementation properly represents a valid DSDT.
292296
unsafe impl AcpiTable for Dsdt {
293297
const SIGNATURE: Signature = Signature::DSDT;
294298

295-
fn header(&self) -> &sdt::SdtHeader {
296-
// Safety: DSDT will always be valid for an SdtHeader at its `self` pointer.
297-
unsafe { &*(self as *const Self as *const sdt::SdtHeader) }
299+
fn header(&self) -> &SdtHeader {
300+
&self.header
298301
}
299302
}
300303

0 commit comments

Comments
 (0)