fix: Prevent panic caused by subtracting with overflow (#36)

This bug occurred if the string was empty (e.g. from a lost connection)
This commit is contained in:
Hubert Pawlak 2023-08-14 13:31:16 +00:00 committed by GitHub
parent 8ef85f3b28
commit 8712a6087b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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)