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.
pull/15429/head
Victor Julien 6 months ago
parent e5650ebcbd
commit 524503b572

@ -67,16 +67,15 @@ static inline void PrefilterAddSids(
if (PrefilterAddSidsResize(pmq, new_size) == 0) { if (PrefilterAddSidsResize(pmq, new_size) == 0) {
// Failed to allocate larger memory for all the SIDS, but // Failed to allocate larger memory for all the SIDS, but
// keep as many as we can. // 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); SCLogDebug("Adding %u sids", sids_size);
// Add SIDs for this pattern to the end of the array // Add SIDs for this pattern to the end of the array
SigIntId *ptr = pmq->rule_id_array + pmq->rule_id_array_cnt; SigIntId *ptr = pmq->rule_id_array + pmq->rule_id_array_cnt;
SigIntId *end = ptr + sids_size; for (uint32_t i = 0; i < sids_size; i++) {
do { *ptr++ = sids[i];
*ptr++ = *sids++; }
} while (ptr != end);
pmq->rule_id_array_cnt += sids_size; pmq->rule_id_array_cnt += sids_size;
} }
} }

Loading…
Cancel
Save