[pbs-devel] [PATCH proxmox-backup] server/worker_task: fix panic on slice range when index is empty

Dominik Csapak d.csapak at proxmox.com
Tue Sep 29 12:22:02 CEST 2020


since len() and MAX_INDEX_TASKS are both usize, they underflow
instead of getting negative values

instead check the sizes and set them accordingly

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/server/worker_task.rs | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/server/worker_task.rs b/src/server/worker_task.rs
index 2b517a79..be689c7f 100644
--- a/src/server/worker_task.rs
+++ b/src/server/worker_task.rs
@@ -418,9 +418,20 @@ fn update_active_workers(new_upid: Option<&UPID>) -> Result<(), Error> {
         }
     });
 
-    let start = (finish_list.len()-MAX_INDEX_TASKS).max(0);
+
+    let start = if finish_list.len() > MAX_INDEX_TASKS {
+        finish_list.len() - MAX_INDEX_TASKS
+    } else {
+        0
+    };
+
     let end = (start+MAX_INDEX_TASKS).min(finish_list.len());
-    let index_raw = render_task_list(&finish_list[start..end]);
+
+    let index_raw = if end > start {
+        render_task_list(&finish_list[start..end])
+    } else {
+        "".to_string()
+    };
 
     replace_file(
         PROXMOX_BACKUP_INDEX_TASK_FN,
-- 
2.20.1






More information about the pbs-devel mailing list