mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: Check that get_slice() returned a big enough slice
This should be guaranteed by GuestMemory and GuestMemoryRegion, but those traits are currently safe, so add checks to guard against incorrect implementations of them. Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
This commit is contained in:
committed by
Rob Bradford
parent
969a3b57a3
commit
2be304b392
@@ -67,8 +67,9 @@ impl TxVirtio {
|
||||
let buf = desc_chain
|
||||
.memory()
|
||||
.get_slice(desc_addr, desc.len() as usize)
|
||||
.map_err(NetQueuePairError::GuestMemory)?
|
||||
.ptr_guard_mut();
|
||||
.map_err(NetQueuePairError::GuestMemory)?;
|
||||
assert!(buf.len() >= desc.len() as usize);
|
||||
let buf = buf.ptr_guard_mut();
|
||||
let iovec = libc::iovec {
|
||||
iov_base: buf.as_ptr() as *mut libc::c_void,
|
||||
iov_len: desc.len() as libc::size_t,
|
||||
@@ -208,8 +209,9 @@ impl RxVirtio {
|
||||
let buf = desc_chain
|
||||
.memory()
|
||||
.get_slice(desc_addr, desc.len() as usize)
|
||||
.map_err(NetQueuePairError::GuestMemory)?
|
||||
.ptr_guard_mut();
|
||||
.map_err(NetQueuePairError::GuestMemory)?;
|
||||
assert!(buf.len() >= desc.len() as usize);
|
||||
let buf = buf.ptr_guard_mut();
|
||||
let iovec = libc::iovec {
|
||||
iov_base: buf.as_ptr() as *mut libc::c_void,
|
||||
iov_len: desc.len() as libc::size_t,
|
||||
|
||||
Reference in New Issue
Block a user