Skip to content

Commit

Permalink
Fix bad pointer deref in talpid-routing::unix::macos::data
Browse files Browse the repository at this point in the history
  • Loading branch information
hulthe committed Feb 13, 2025
1 parent c94e264 commit 170916b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion talpid-routing/src/unix/macos/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,12 @@ impl Interface {
actual_size: buffer.len(),
});
}
let header: libc::if_msghdr = unsafe { std::ptr::read(buffer.as_ptr() as *const _) };
let header = buffer.as_ptr().cast::<libc::if_msghdr>();

// SAFETY:
// - `buffer` points to initialized memory of the correct size.
// - if_msghdr is a C struct, and valid for any bit pattern
let header: libc::if_msghdr = unsafe { header.read_unaligned() };
// let payload = buffer[INTERFACE_MESSAGE_HEADER_SIZE..header.ifm_msglen.into()].to_vec();
Ok(Self { header })
}
Expand Down

0 comments on commit 170916b

Please sign in to comment.