Skip to content

Commit

Permalink
Enforce undocumented_unsafe_blocks clippy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbert Fabritius committed Feb 6, 2024
1 parent 629f9f0 commit bc44b2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion heimlig/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
ed25519-dalek = { version = "2.0.0", default-features = false, features = ["zeroize", "rand_core"] }

[build-dependencies]
cbindgen = { version = "0.26.0", default-features = false }
cbindgen = { version = "0.26.0", default-features = false }

[lints.clippy]
undocumented_unsafe_blocks = "warn"
10 changes: 6 additions & 4 deletions heimlig/src/integration/raw_jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,15 @@ impl RequestRaw {
/// valid `RequestRaw` instance.
///
pub unsafe fn from_raw(ptr: *const u8) -> Result<Self, ValidationError> {
// Unsafe: Pointer and size must be checked by integrator
// SAFETY: Pointer and size must be checked by integrator
let tag: u8 = unsafe { *ptr };

// Validate tag value. Invalid tag values cause UB when transmuted into an enum.
if tag >= RequestRaw::COUNT as u8 {
return Err(ValidationError::InvalidTagValue);
}

// Safety: All members of RequestRaw are valid for all possible values found in memory
// SAFETY: All members of RequestRaw are valid for all possible values found in memory
Ok(*ptr.cast::<RequestRaw>())
}

Expand Down Expand Up @@ -1695,15 +1695,15 @@ impl ResponseRaw {
/// valid `ResponseRaw` instance.
///
pub unsafe fn from_raw(ptr: *const u8) -> Result<Self, ValidationError> {
// Unsafe: Pointer and size must be checked by integrator
// SAFETY: Pointer and size must be checked by integrator
let tag: u8 = unsafe { *ptr };

// Validate tag value. Invalid tag values cause UB when transmuted into an enum.
if tag >= ResponseRaw::COUNT as u8 {
return Err(ValidationError::InvalidTagValue);
}

// Safety: All members of RequestRaw are valid for all possible values found in memory
// SAFETY: All members of RequestRaw are valid for all possible values found in memory
Ok(*ptr.cast::<ResponseRaw>())
}
}
Expand Down Expand Up @@ -1965,6 +1965,7 @@ fn check_pointer_and_size<'a>(
if !validator(data, size) {
return Err(ValidationError::InvalidPointer);
}
// SAFETY: Checked by integrator-provided validator
Ok(unsafe { slice::from_raw_parts(data, size as usize) })
}

Expand All @@ -1980,6 +1981,7 @@ fn check_mut_pointer_and_size<'a>(
if !validator(data, size) {
return Err(ValidationError::InvalidPointer);
}
// SAFETY: Checked by integrator-provided validator
Ok(unsafe { slice::from_raw_parts_mut(data, size as usize) })
}

Expand Down

0 comments on commit bc44b2d

Please sign in to comment.