From 524503b57251f323c142f053113cb0b1af141c5c Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sun, 10 May 2026 12:40:46 +0200 Subject: [PATCH] detect/prefilter: rewrite loop to assist scan-build Also address a theoretical edge case where memory allocation failure could lead to overrunning the sids array. --- src/util-prefilter.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/util-prefilter.h b/src/util-prefilter.h index 125120480d..75c2919807 100644 --- a/src/util-prefilter.h +++ b/src/util-prefilter.h @@ -67,16 +67,15 @@ static inline void PrefilterAddSids( if (PrefilterAddSidsResize(pmq, new_size) == 0) { // Failed to allocate larger memory for all the SIDS, but // keep as many as we can. - sids_size = pmq->rule_id_array_size - pmq->rule_id_array_cnt; + sids_size = MIN(sids_size, (pmq->rule_id_array_size - pmq->rule_id_array_cnt)); } } SCLogDebug("Adding %u sids", sids_size); // Add SIDs for this pattern to the end of the array SigIntId *ptr = pmq->rule_id_array + pmq->rule_id_array_cnt; - SigIntId *end = ptr + sids_size; - do { - *ptr++ = *sids++; - } while (ptr != end); + for (uint32_t i = 0; i < sids_size; i++) { + *ptr++ = sids[i]; + } pmq->rule_id_array_cnt += sids_size; } }