]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
update_suggested_effort: avoid assert if the pqueue has emptied
authorMicah Elizabeth Scott <beth@torproject.org>
Wed, 22 Feb 2023 01:06:17 +0000 (17:06 -0800)
committerMicah Elizabeth Scott <beth@torproject.org>
Wed, 10 May 2023 14:37:11 +0000 (07:37 -0700)
top_of_rend_pqueue_is_worthwhile requires a nonempty queue.

src/feature/hs/hs_circuit.c
src/feature/hs/hs_service.c

index 3f17373b6900651ecf0f0d523124cfcb536aa38a..0ac47ee19fc690f3ef347bd8215bd8869b1e9cb7 100644 (file)
@@ -722,9 +722,9 @@ count_service_rp_circuits_pending(hs_service_t *service)
   return count;
 }
 
-/** Peek at the top entry on the pending rend pqueue. If its level of
- * effort is at least what we're suggesting for that service right now,
- * return 1, else return 0.
+/** Peek at the top entry on the pending rend pqueue, which must not be empty.
+ * If its level of effort is at least what we're suggesting for that service
+ * right now, return 1, else return 0.
  */
 int
 top_of_rend_pqueue_is_worthwhile(hs_pow_service_state_t *pow_state)
index b50f996fbdea3e3e58947623675b0152b6a5a02c..d67fead79111294810352ddf1da319938333cbcb 100644 (file)
@@ -2689,7 +2689,8 @@ update_suggested_effort(hs_service_t *service, time_t now)
     /* If we had a queue during this period, and the current top of queue
      * is at or above the suggested effort, we should re-estimate the effort.
      * Otherwise, it can stay the same (no change to effort). */
-    if (top_of_rend_pqueue_is_worthwhile(pow_state)) {
+    if (smartlist_len(pow_state->rend_request_pqueue) > 0 &&
+        top_of_rend_pqueue_is_worthwhile(pow_state)) {
       pow_state->suggested_effort = (uint32_t)(pow_state->total_effort /
                                                pow_state->rend_handled);
     }