]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/flowbits: only walk over array if needed
authorJuliana Fajardini <jufajardini@gmail.com>
Fri, 17 Jan 2025 20:41:19 +0000 (17:41 -0300)
committerVictor Julien <victor@inliniac.net>
Wed, 19 Feb 2025 08:21:32 +0000 (09:21 +0100)
For setting s->init_data for flowbit rules impacted by `set`, we can
first check whether this will be needed, and *then* walk over the
flowbits array.

src/detect-flowbits.c

index 937743dc054983eb50ab578fd0339931a8ec25d1..8efb93ed793fac6a0b0d8e45dc4dfac665d6c51a 100644 (file)
@@ -624,11 +624,11 @@ int DetectFlowbitsAnalyze(DetectEngineCtx *de_ctx)
             SCLogDebug("SET flowbit %s/%u: SID %u", varname, i,
                     de_ctx->sig_array[array[i].set_sids[x]]->id);
         }
-        for (uint32_t x = 0; x < array[i].isset_sids_idx; x++) {
-            Signature *s = de_ctx->sig_array[array[i].isset_sids[x]];
-            SCLogDebug("GET flowbit %s/%u: SID %u", varname, i, s->id);
+        if (to_state) {
+            for (uint32_t x = 0; x < array[i].isset_sids_idx; x++) {
+                Signature *s = de_ctx->sig_array[array[i].isset_sids[x]];
+                SCLogDebug("GET flowbit %s/%u: SID %u", varname, i, s->id);
 
-            if (to_state) {
                 s->init_data->init_flags |= SIG_FLAG_INIT_STATE_MATCH;
                 SCLogDebug("made SID %u stateful because it depends on "
                         "stateful rules that set flowbit %s", s->id, varname);