fix: Prevent panic caused by subtracting with overflow

This bug occurred if the string was empty (e.g. from a lost connection)
This commit is contained in:
hubertpawlak 2023-07-18 21:48:26 +02:00
parent 8ef85f3b28
commit fdf6c87e73
No known key found for this signature in database
GPG key ID: E29D252D06BC2A5E
2 changed files with 2 additions and 2 deletions

View file

@ -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)

View file

@ -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)