From a98b946aed4894a698cef07b5137e0a76a07d64c Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 23 Mar 2023 13:48:04 +0100 Subject: [PATCH] fix : dont send specials characters We don't want to send new line (10) and carriage return (13) to the receiver. Signed-off-by: Maxime --- src/vmm/src/devices/mod.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/vmm/src/devices/mod.rs b/src/vmm/src/devices/mod.rs index d4f09c7..5e802b3 100644 --- a/src/vmm/src/devices/mod.rs +++ b/src/vmm/src/devices/mod.rs @@ -11,10 +11,15 @@ pub struct Writer { impl Write for Writer { fn write(&mut self, buf: &[u8]) -> Result { - let s = String::from_utf8_lossy(buf); - self.tx - .send(s.to_string()) - .map_err(|_| std::io::Error::new(std::io::ErrorKind::Other, "Error sending data"))?; + if buf.len() > 0 && (buf[0] != 10 && buf[0] != 13) { + let s = String::from_utf8_lossy(buf).to_string(); + self.tx.send(s).map_err(|_| { + std::io::Error::new( + std::io::ErrorKind::Other, + "Error while sending data to channel", + ) + })?; + } Ok(buf.len()) }