mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vm-virtio: checked_descriptor: Add unit test for address overflow
Submit a descriptor whose addr plus len would wrap around the u64 address space and verify CheckedDescriptorIter rejects it without panicking, with failed_addr returning the descriptor's address. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
acda9b1380
commit
e790d3b7bc
@@ -377,4 +377,19 @@ mod unit_tests {
|
||||
let result = it.next().expect("must yield an item");
|
||||
assert_eq!(result.unwrap_err(), GuestAddress(addr));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_descriptor_with_address_overflow() {
|
||||
// A descriptor whose addr plus len would wrap around the u64 address
|
||||
// space must be rejected without panicking.
|
||||
const MEM_SIZE: usize = 128 * 1024;
|
||||
let addr = u64::MAX - 100;
|
||||
let len: u32 = 1024;
|
||||
let (_mem, mem_atomic, mut queue) = setup_vq(MEM_SIZE, addr, len, 0);
|
||||
let mem_guard = mem_atomic.memory();
|
||||
let mut chain = queue.pop_descriptor_chain(mem_guard).unwrap();
|
||||
let mut it = chain.checked_iter(None);
|
||||
let result = it.next().expect("must yield an item");
|
||||
assert_eq!(result.unwrap_err(), GuestAddress(addr));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user