Skip to content

Commit

Permalink
Fix bug in priority queue remove function
Browse files Browse the repository at this point in the history
The short circuit in the remove function when the element is the last in the
heap, failed to add the removed slot back to the freelist.

Fixes #22644

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #22646)
  • Loading branch information
paulidale authored and hlandau committed Nov 8, 2023
1 parent ec0d22f commit a031087
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ssl/priority_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,14 @@ void *ossl_pqueue_remove(OSSL_PQUEUE *pq, size_t elem)

ASSERT_USED(pq, n);

if (n == pq->htop - 1)
if (n == pq->htop - 1) {
pq->elements[elem].posn = pq->freelist;
pq->freelist = elem;
#ifndef NDEBUG
pq->elements[elem].used = 0;
#endif
return pq->heap[--pq->htop].data;
}
if (n > 0)
pqueue_force_bottom(pq, n);
return ossl_pqueue_pop(pq);
Expand Down

0 comments on commit a031087

Please sign in to comment.