Skip to content

Commit 592be4a

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 77d825c commit 592be4a

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
@@ -591,8 +591,8 @@ impl<T: GuestMemory + ?Sized> Bytes<GuestAddress> for T {
591591
self.try_access(
592592
buf.len(),
593593
addr,
594-
|offset, _count, caddr, region| -> Result<usize> {
595-
region.write(&buf[offset..], caddr)
594+
|offset, count, caddr, region| -> Result<usize> {
595+
region.write(&buf[offset..(offset + count)], caddr)
596596
},
597597
)
598598
}
@@ -601,8 +601,8 @@ impl<T: GuestMemory + ?Sized> Bytes<GuestAddress> for T {
601601
self.try_access(
602602
buf.len(),
603603
addr,
604-
|offset, _count, caddr, region| -> Result<usize> {
605-
region.read(&mut buf[offset..], caddr)
604+
|offset, count, caddr, region| -> Result<usize> {
605+
region.read(&mut buf[offset..(offset + count)], caddr)
606606
},
607607
)
608608
}

0 commit comments

Comments
 (0)