From: Lukas Sismis Date: Tue, 22 Jul 2025 07:57:38 +0000 (+0200) Subject: hyperscan: prevent LTO opmitizing out hash calculation X-Git-Tag: suricata-8.0.1~93 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e4a406d375bad00ea4d73d49cb1ad777042c105c;p=thirdparty%2Fsuricata.git hyperscan: prevent LTO opmitizing out hash calculation Since cached_hash was updated through reference (hash), it seems LTO did not notice this and optimized the whole code block, returning zero. This in turn caused all caches to have the same name and to overwrite. On subsequent runs, only the last cache was loaded for all SGHs causing wrong MPM assignment. Ticket: 7824 --- diff --git a/src/util-mpm-hs-cache.c b/src/util-mpm-hs-cache.c index 4aaf5da84c..2e58676fa9 100644 --- a/src/util-mpm-hs-cache.c +++ b/src/util-mpm-hs-cache.c @@ -222,14 +222,12 @@ cleanup: uint64_t HSHashDb(const PatternDatabase *pd) { - uint64_t cached_hash = 0; - uint32_t *hash = (uint32_t *)(&cached_hash); + uint32_t hash[2] = { 0 }; hashword2(&pd->pattern_cnt, 1, &hash[0], &hash[1]); for (uint32_t i = 0; i < pd->pattern_cnt; i++) { SCHSCachePatternHash(pd->parray[i], &hash[0], &hash[1]); } - - return cached_hash; + return ((uint64_t)hash[1] << 32) | hash[0]; } void HSSaveCacheIterator(void *data, void *aux)