Skip to content

Commit 82ac114

Browse files
liuwlikebreath
authored andcommitted
virtio-devices: vsock: handle short read in muxer
Use read_exact to make sure we really get the minimum number of bytes. Fixes: cloud-hypervisor#6621 Signed-off-by: Wei Liu <[email protected]>
1 parent 2ffd5df commit 82ac114

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

virtio-devices/src/vsock/unix/muxer.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,10 @@ impl VsockMuxer {
495495
const MIN_COMMAND_LEN: usize = 10;
496496

497497
// Bring in the minimum number of bytes that we should be able to read.
498-
if command.len < MIN_COMMAND_LEN {
499-
command.len += stream
500-
.read(&mut command.buf[command.len..MIN_COMMAND_LEN])
501-
.map_err(Error::UnixRead)?;
502-
}
498+
stream
499+
.read_exact(&mut command.buf[command.len..MIN_COMMAND_LEN])
500+
.map_err(Error::UnixRead)?;
501+
command.len = MIN_COMMAND_LEN;
503502

504503
// Now, finish reading the destination port number, by bringing in one byte at a time,
505504
// until we reach an EOL terminator (or our buffer space runs out). Yeah, not

0 commit comments

Comments
 (0)