From 8712a6087bbe0dffb7b565cc430b05d094666599 Mon Sep 17 00:00:00 2001 From: Hubert Pawlak <87566321+hubertpawlak@users.noreply.github.com> Date: Mon, 14 Aug 2023 13:31:16 +0000 Subject: [PATCH] fix: Prevent panic caused by subtracting with overflow (#36) This bug occurred if the string was empty (e.g. from a lost connection) --- rups/src/blocking/mod.rs | 2 +- rups/src/tokio/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rups/src/blocking/mod.rs b/rups/src/blocking/mod.rs index a0f2d5d..a95526e 100644 --- a/rups/src/blocking/mod.rs +++ b/rups/src/blocking/mod.rs @@ -138,7 +138,7 @@ impl TcpConnection { if debug { eprint!("DEBUG <- {}", raw); } - raw = raw[..raw.len() - 1].to_string(); // Strip off \n + raw = raw.trim_end_matches('\n').to_string(); // Strip off \n // Parse args by splitting whitespace, minding quotes for args with multiple words let args = shell_words::split(&raw) diff --git a/rups/src/tokio/mod.rs b/rups/src/tokio/mod.rs index dc6677a..cf1abf9 100644 --- a/rups/src/tokio/mod.rs +++ b/rups/src/tokio/mod.rs @@ -144,7 +144,7 @@ impl TcpConnection { if debug { eprint!("DEBUG <- {}", raw); } - raw = raw[..raw.len() - 1].to_string(); // Strip off \n + raw = raw.trim_end_matches('\n').to_string(); // Strip off \n // Parse args by splitting whitespace, minding quotes for args with multiple words let args = shell_words::split(&raw)