Skip to content

Commit ef0b0fb

Browse files
committed
virtio/fs/macos: fix INIT_BINARY read with offset
We already fixed this for Linux a while ago, do the same for the macOS implementation. Signed-off-by: Sergio Lopez <[email protected]>
1 parent 1e3c568 commit ef0b0fb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/devices/src/virtio/fs/macos/passthrough.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,15 @@ impl FileSystem for PassthroughFs {
12381238
debug!("read: {:?}", inode);
12391239
#[cfg(not(feature = "efi"))]
12401240
if inode == self.init_inode {
1241-
return w.write(&INIT_BINARY[offset as usize..(offset + (size as u64)) as usize]);
1241+
let off: usize = offset
1242+
.try_into()
1243+
.map_err(|_| io::Error::from_raw_os_error(libc::EINVAL))?;
1244+
let len = if off + (size as usize) < INIT_BINARY.len() {
1245+
size as usize
1246+
} else {
1247+
INIT_BINARY.len() - off
1248+
};
1249+
return w.write(&INIT_BINARY[off..(off + len)]);
12421250
}
12431251

12441252
let data = self

0 commit comments

Comments
 (0)