From 25bf59f238b14e1d21044c963979b9a29b273ac2 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 12 Mar 2026 08:46:44 +0100 Subject: [PATCH] util/spm: explicit needle_len is u16 So, stack allocation is bounded Ticket: 8001 --- src/util-spm-mm.c | 4 ++-- src/util-spm-mm.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util-spm-mm.c b/src/util-spm-mm.c index 492459582b..ddbd3e79ba 100644 --- a/src/util-spm-mm.c +++ b/src/util-spm-mm.c @@ -37,11 +37,11 @@ * Convert haystack data to lowercase before inspecting it with * `memmem`. Do this in a sliding window manner. */ static const uint8_t *SCMemimem(const uint8_t *haystack, uint32_t haystack_len, - const uint8_t *needle, const uint32_t needle_len) + const uint8_t *needle, const uint16_t needle_len) { if (needle_len > haystack_len) return NULL; - uint32_t slice_size = MAX(MIN(haystack_len, 128), needle_len * 3); + uint32_t slice_size = MAX(MIN(haystack_len, 128), (uint32_t)needle_len * 3); uint8_t slice[slice_size]; uint32_t o = 0; do { diff --git a/src/util-spm-mm.h b/src/util-spm-mm.h index a5b0c93362..e3ed87c741 100644 --- a/src/util-spm-mm.h +++ b/src/util-spm-mm.h @@ -26,7 +26,7 @@ #ifdef HAVE_MEMMEM typedef struct SpmMmCtx_ { - uint32_t needle_len; + uint16_t needle_len; int nocase; uint8_t needle[]; } SpmMmCtx;