From 82ac114b8aba9a4264925335f93a7f1069c86196 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Wed, 31 Jul 2024 06:36:00 +0000 Subject: [PATCH] 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 --- virtio-devices/src/vsock/unix/muxer.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/virtio-devices/src/vsock/unix/muxer.rs b/virtio-devices/src/vsock/unix/muxer.rs index 59bac4e70..ed3b62b5b 100644 --- a/virtio-devices/src/vsock/unix/muxer.rs +++ b/virtio-devices/src/vsock/unix/muxer.rs @@ -495,11 +495,10 @@ impl VsockMuxer { const MIN_COMMAND_LEN: usize = 10; // Bring in the minimum number of bytes that we should be able to read. - if command.len < MIN_COMMAND_LEN { - command.len += stream - .read(&mut command.buf[command.len..MIN_COMMAND_LEN]) - .map_err(Error::UnixRead)?; - } + stream + .read_exact(&mut command.buf[command.len..MIN_COMMAND_LEN]) + .map_err(Error::UnixRead)?; + command.len = MIN_COMMAND_LEN; // 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