Skip to content

Commit b321d9d

Browse files
authored
style(staterestore): add safety docs and harden wants_to_exit (#3868)
1 parent d318515 commit b321d9d

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

crates/libafl_bolts/src/staterestore.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ where
205205
assert!(size_of::<StateShMemContent>() + len <= self.shmem.len());
206206

207207
let shmem_content = self.content_mut();
208+
// # Safety
209+
// `buf` is large enough to hold `[u8; 16]` and is properly aligned (u8 alignment is 1),
210+
// and `buf_len` points to a valid field in shared memory.
208211
unsafe {
209212
ptr::write_volatile(
210213
shmem_content.buf.as_mut_ptr().cast::<[u8; 16]>(),
@@ -220,10 +223,14 @@ where
220223
let len = EXITING_MAGIC.len();
221224
assert!(size_of::<StateShMemContent>() + len <= self.shmem.len());
222225
let content = self.content();
226+
// # Safety
227+
// `content.buf_len` points to a valid field in the shared memory map.
223228
let buf_len = unsafe { read_volatile(&raw const content.buf_len) };
224229
if buf_len != len {
225230
return false;
226231
}
232+
// # Safety
233+
// `content.buf` is checked above to contain at least 16 bytes and is properly aligned (u8 alignment is 1).
227234
let magic = unsafe { read_volatile(content.buf.as_ptr().cast::<[u8; 16]>()) };
228235
magic == *EXITING_MAGIC
229236
}

0 commit comments

Comments
 (0)