Safe function dereferences a raw pointer parameter
ID |
rust.correctness.functions_expecting_raw_pointer_args |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Api Design |
Language |
Rust |
Description
This function takes a raw pointer and dereferences it, yet its signature is safe, so any caller can pass a dangling or null pointer without writing unsafe. Mark the function unsafe fn so the caller has to acknowledge the contract, or validate the pointer and expose a reference instead.
Rationale
This function takes a raw pointer and dereferences it, yet its signature is safe, so any caller can pass a dangling or null pointer without writing unsafe. Mark the function unsafe fn so the caller has to acknowledge the contract, or validate the pointer and expose a reference instead.
The following code illustrates the pattern detected by this rule:
// FLAGGED: Safe function dereferences a raw pointer parameter
fn read_byte(source: *const u8) -> u8 {
unsafe { *source }
}