Description
In the test_size_demi_sgarray_t() unit test function, we are relying on the compiler to compute the size of SockAddr.
This is against the idea of this test: ensuring that the structure matches a size that we want. This property is important to avoid UB when crossing language boundaries.
Code Snippets
|
fn test_size_demi_sgarray_t() -> Result<(), anyhow::Error> { |
|
// Size of a void pointer. |
|
const SGA_BUF_SIZE: usize = 8; |
|
// Size of a u32. |
|
const SGA_NUMSEGS_SIZE: usize = 4; |
|
// Size of an array of demi_sgaseg_t structures. |
|
const SGA_SEGS_SIZE: usize = mem::size_of::<demi_sgaseg_t>() * DEMI_SGARRAY_MAXLEN; |
|
// Size of a SockAddr structure. |
|
const SGA_ADDR_SIZE: usize = mem::size_of::<SockAddr>(); |
|
// Size of a demi_sgarray_t structure. |
|
crate::ensure_eq!( |
|
mem::size_of::<demi_sgarray_t>(), |
|
SGA_BUF_SIZE + SGA_NUMSEGS_SIZE + SGA_SEGS_SIZE + SGA_ADDR_SIZE |
|
); |
|
Ok(()) |
Description
In the
test_size_demi_sgarray_t()unit test function, we are relying on the compiler to compute the size ofSockAddr.This is against the idea of this test: ensuring that the structure matches a size that we want. This property is important to avoid UB when crossing language boundaries.
Code Snippets
demikernel/src/rust/runtime/types/memory.rs
Lines 71 to 85 in ffaf885