]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
alert: fixes leak in ThresholdHandlePacketRule
authorPhilippe Antoine <contact@catenacyber.fr>
Tue, 5 Oct 2021 19:14:18 +0000 (21:14 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 5 Oct 2021 19:32:34 +0000 (21:32 +0200)
ThresholdHandlePacketRule may take ownership of an allocated
DetectThresholdEntry, and places it in a position of the
array th_entry. But it never got released

src/detect-engine-threshold.c

index 70c4e4f567643317ab301bbefd93c051dc334729..67eccd678423e3c9d05060a910baa56987b6bd53 100644 (file)
@@ -727,8 +727,14 @@ void ThresholdHashAllocate(DetectEngineCtx *de_ctx)
  */
 void ThresholdContextDestroy(DetectEngineCtx *de_ctx)
 {
-    if (de_ctx->ths_ctx.th_entry != NULL)
+    if (de_ctx->ths_ctx.th_entry != NULL) {
+        for (uint32_t i = 0; i < de_ctx->ths_ctx.th_size; i++) {
+            if (de_ctx->ths_ctx.th_entry[i] != NULL) {
+                SCFree(de_ctx->ths_ctx.th_entry[i]);
+            }
+        }
         SCFree(de_ctx->ths_ctx.th_entry);
+    }
     SCMutexDestroy(&de_ctx->ths_ctx.threshold_table_lock);
 }