Jelajahi Sumber

Catch out of bounds notification indices

Mark Rousskov 5 tahun lalu
induk
melakukan
ca9c31ab13
1 mengubah file dengan 4 tambahan dan 1 penghapusan
  1. 4 1
      src/db/notifications.rs

+ 4 - 1
src/db/notifications.rs

@@ -73,7 +73,10 @@ pub async fn delete_ping(
                 .await
                 .context("failed to get ordering")?;
 
-            let notification_id: i64 = notifications[idx.get() - 1].get(0);
+            let notification_id: i64 = notifications
+                .get(idx.get() - 1)
+                .ok_or_else(|| anyhow::anyhow!("No such notification with index {}", idx.get()))?
+                .get(0);
 
             t.execute(
                 "DELETE FROM notifications WHERE notification_id = $1",