30 lines
1.5 KiB
Diff
30 lines
1.5 KiB
Diff
# UNDF: UNDF-2026-000000318
|
|
diff --git a/src/core/or/scheduler_kist.c b/src/core/or/scheduler_kist.c
|
|
index abc1234..def5678 100644
|
|
--- a/src/core/or/scheduler_kist.c
|
|
+++ b/src/core/or/scheduler_kist.c
|
|
@@ -753,15 +753,13 @@ kist_scheduler_run(void)
|
|
/* Re-add any channels we need to */
|
|
if (to_readd) {
|
|
SMARTLIST_FOREACH_BEGIN(to_readd, channel_t *, readd_chan) {
|
|
scheduler_set_channel_state(readd_chan, SCHED_CHAN_PENDING);
|
|
- if (!smartlist_contains(cp, readd_chan)) {
|
|
- if (!SCHED_BUG(readd_chan->sched_heap_idx != -1, readd_chan)) {
|
|
- /* XXXX Note that the check above is in theory redundant with
|
|
- * the smartlist_contains check. But let's make sure we're
|
|
- * not messing anything up, and leave them both for now. */
|
|
- smartlist_pqueue_add(cp, scheduler_compare_channels,
|
|
- offsetof(channel_t, sched_heap_idx), readd_chan);
|
|
- }
|
|
+ /*
|
|
+ * CWE-407 fix: sched_heap_idx == -1 is the O(1) test for "not already
|
|
+ * in the pending pqueue cp". The previous smartlist_contains(cp, ...)
|
|
+ * was an O(|cp|) linear scan that the comment already called "in theory
|
|
+ * redundant". Remove it; rely on the heap-index invariant alone.
|
|
+ */
|
|
+ if (readd_chan->sched_heap_idx == -1) {
|
|
+ smartlist_pqueue_add(cp, scheduler_compare_channels,
|
|
+ offsetof(channel_t, sched_heap_idx), readd_chan);
|
|
}
|
|
} SMARTLIST_FOREACH_END(readd_chan);
|
|
smartlist_free(to_readd);
|