Skip to content

Commit

Permalink
greq/pld_report: add SAFETY comments to unsafe casts
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos López <carlos.lopez@suse.com>
  • Loading branch information
00xc committed Nov 23, 2023
1 parent b9054f9 commit de614dc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/greq/pld_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ impl SnpReportRequest {
.get(..size_of::<Self>())
.ok_or_else(SvsmReqError::invalid_parameter)?;

// SAFETY: SnpReportRequest has no invalid representations, as it is
// comprised entirely of integer types. It is repr(packed), so its
// required alignment is simply 1. We have checked the size, so this
// is entirely safe.
let request = unsafe { &*buffer.as_ptr().cast::<Self>() };

if !request.is_reserved_clear() {
Expand Down Expand Up @@ -89,6 +93,10 @@ impl SnpReportResponse {
.get(..size_of::<Self>())
.ok_or_else(SvsmReqError::invalid_parameter)?;

// SAFETY: SnpReportResponse has no invalid representations, as it is
// comprised entirely of integer types. It is repr(packed), so its
// required alignment is simply 1. We have checked the size, so this
// is entirely safe.
let response = unsafe { &*buffer.as_ptr().cast::<Self>() };
Ok(response)
}
Expand Down

0 comments on commit de614dc

Please sign in to comment.