tests: Fix UB in AF_XDP test

pull/846/head
arctic-alpaca 10 months ago
parent b1769678f4
commit ef9284113b
No known key found for this signature in database
GPG Key ID: F911E2A7F537230E

@ -32,9 +32,9 @@ fn af_xdp() {
struct PacketMap(MaybeUninit<[u8; 4096]>);
// Safety: don't access alloc down the line.
let mut alloc = Box::new(PacketMap(MaybeUninit::uninit()));
let mut alloc = Box::new(PacketMap(MaybeUninit::zeroed()));
let umem = {
// Safety: this is a shared buffer between the kernel and us, uninitialized memory is valid.
// Safety: Zeroed memory is valid for u8 arrays.
let mem = unsafe { alloc.0.assume_init_mut() }.as_mut().into();
// Safety: we cannot access `mem` further down the line because it falls out of scope.
unsafe { Umem::new(UmemConfig::default(), mem).unwrap() }

Loading…
Cancel
Save