fix #3017: check array boundaries before using

else we panic here

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-09-21 09:12:32 +02:00 committed by Dietmar Maurer
parent f4dc47a805
commit 5e39918fe1

View File

@ -210,7 +210,7 @@ pub fn upid_read_status(upid: &UPID) -> Result<TaskState, Error> {
file.read_to_end(&mut data)?; file.read_to_end(&mut data)?;
// task logs should end with newline, we do not want it here // task logs should end with newline, we do not want it here
if data[data.len()-1] == b'\n' { if data.len() > 0 && data[data.len()-1] == b'\n' {
data.pop(); data.pop();
} }
@ -218,7 +218,7 @@ pub fn upid_read_status(upid: &UPID) -> Result<TaskState, Error> {
let mut start = 0; let mut start = 0;
for pos in (0..data.len()).rev() { for pos in (0..data.len()).rev() {
if data[pos] == b'\n' { if data[pos] == b'\n' {
start = pos + 1; start = data.len().min(pos + 1);
break; break;
} }
} }