Skip to content

Commit

Permalink
fix : dont send specials characters
Browse files Browse the repository at this point in the history
We don't want to send new line (10)  and carriage return (13) to the receiver.

Signed-off-by: Maxime <[email protected]>
  • Loading branch information
Maxtho8 committed Mar 23, 2023
1 parent 2cc0e25 commit a98b946
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/vmm/src/devices/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ pub struct Writer {

impl Write for Writer {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
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())
}

Expand Down

0 comments on commit a98b946

Please sign in to comment.