Skip to content

Commit 9bcd5ac

Browse files
committed
Bytes: Fix read() and write()
read() and write() must not ignore the `count` parameter: The mappings passed into the `try_access()` closure are only valid for up to `count` bytes, not more. Signed-off-by: Hanna Czenczek <[email protected]>
1 parent 3540534 commit 9bcd5ac

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/guest_memory.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,8 @@ impl<T: GuestMemory + ?Sized> Bytes<GuestAddress> for T {
464464
self.try_access(
465465
buf.len(),
466466
addr,
467-
|offset, _count, caddr, region| -> Result<usize> {
468-
region.write(&buf[offset..], caddr)
467+
|offset, count, caddr, region| -> Result<usize> {
468+
region.write(&buf[offset..(offset + count)], caddr)
469469
},
470470
)
471471
}
@@ -474,8 +474,8 @@ impl<T: GuestMemory + ?Sized> Bytes<GuestAddress> for T {
474474
self.try_access(
475475
buf.len(),
476476
addr,
477-
|offset, _count, caddr, region| -> Result<usize> {
478-
region.read(&mut buf[offset..], caddr)
477+
|offset, count, caddr, region| -> Result<usize> {
478+
region.read(&mut buf[offset..(offset + count)], caddr)
479479
},
480480
)
481481
}

0 commit comments

Comments
 (0)