From fdf6c87e7314f15af0d6c6e54f580583fdd4bf28 Mon Sep 17 00:00:00 2001 From: hubertpawlak <87566321+hubertpawlak@users.noreply.github.com> Date: Tue, 18 Jul 2023 21:48:26 +0200 Subject: [PATCH] fix: Prevent panic caused by subtracting with overflow 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)