Fixed incorrect copy size reading/writing virtqueue descriptors

This commit is contained in:
Bruce Leidl 2019-10-02 15:41:52 -04:00
parent 2a442775dd
commit d24c5d9ea6

View File

@ -356,7 +356,7 @@ impl Descriptor {
pub fn read_from(&self, memory: &GuestRam, offset: usize, buf: &mut[u8]) -> usize { pub fn read_from(&self, memory: &GuestRam, offset: usize, buf: &mut[u8]) -> usize {
let sz = cmp::min(buf.len(), self.remaining(offset)); let sz = cmp::min(buf.len(), self.remaining(offset));
if sz > 0 { if sz > 0 {
memory.read_bytes(self.addr + offset as u64, buf).unwrap(); memory.read_bytes(self.addr + offset as u64, &mut buf[..sz]).unwrap();
} }
sz sz
} }
@ -364,7 +364,7 @@ impl Descriptor {
pub fn write_to(&self, memory: &GuestRam, offset: usize, buf: &[u8]) -> usize { pub fn write_to(&self, memory: &GuestRam, offset: usize, buf: &[u8]) -> usize {
let sz = cmp::min(buf.len(), self.remaining(offset)); let sz = cmp::min(buf.len(), self.remaining(offset));
if sz > 0 { if sz > 0 {
memory.write_bytes(self.addr + offset as u64, buf).unwrap(); memory.write_bytes(self.addr + offset as u64, &buf[..sz]).unwrap();
} }
sz sz
} }