all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] server/worker_task: fix panic on slice range when index is empty
Date: Tue, 29 Sep 2020 12:22:02 +0200	[thread overview]
Message-ID: <20200929102202.17236-1-d.csapak@proxmox.com> (raw)

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





                 reply	other threads:[~2020-09-29 10:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200929102202.17236-1-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal