virtio-devices: vsock: handle short read in muxer

Use read_exact to make sure we really get the minimum number of bytes.

Fixes: #6621
Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2024-07-31 06:36:00 +00:00 committed by Bo Chen
parent 2ffd5df018
commit 82ac114b8a

View File

@ -495,11 +495,10 @@ impl VsockMuxer {
const MIN_COMMAND_LEN: usize = 10; const MIN_COMMAND_LEN: usize = 10;
// Bring in the minimum number of bytes that we should be able to read. // Bring in the minimum number of bytes that we should be able to read.
if command.len < MIN_COMMAND_LEN { stream
command.len += stream .read_exact(&mut command.buf[command.len..MIN_COMMAND_LEN])
.read(&mut command.buf[command.len..MIN_COMMAND_LEN]) .map_err(Error::UnixRead)?;
.map_err(Error::UnixRead)?; command.len = MIN_COMMAND_LEN;
}
// Now, finish reading the destination port number, by bringing in one byte at a time, // Now, finish reading the destination port number, by bringing in one byte at a time,
// until we reach an EOL terminator (or our buffer space runs out). Yeah, not // until we reach an EOL terminator (or our buffer space runs out). Yeah, not