]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/magic: fix crash on rule reloading
authorAngelo Mirabella <amirabella@lastline.com>
Tue, 26 May 2020 17:00:06 +0000 (18:00 +0100)
committerJeff Lucovsky <jeff@lucovsky.org>
Sat, 28 Nov 2020 13:09:01 +0000 (08:09 -0500)
This changseset fixes a bug causing a segmentation fault.
When rules are reloaded and a rule using libmagic matches, suricata
crashes due to an improper reinitialization of the thread contexts.

Bug: #3726
(cherry picked from commit c72069c3b2c276a3b6cef627f1d8983d2df25bbe)

src/detect-filemagic.c

index 634b8e803a5a8fb74c8550b37b4d8679c6025e26..3590c797870c4b0c712dec7fdf807a26952c6454 100644 (file)
@@ -415,13 +415,10 @@ static int DetectFilemagicSetup (DetectEngineCtx *de_ctx, Signature *s, const ch
     if (filemagic == NULL)
         return -1;
 
-    if (g_magic_thread_ctx_id == -1) {
-        g_magic_thread_ctx_id = DetectRegisterThreadCtxFuncs(de_ctx, "filemagic",
-                DetectFilemagicThreadInit, (void *)filemagic,
-                DetectFilemagicThreadFree, 1);
-        if (g_magic_thread_ctx_id == -1)
-            goto error;
-    }
+    g_magic_thread_ctx_id = DetectRegisterThreadCtxFuncs(de_ctx, "filemagic",
+            DetectFilemagicThreadInit, (void *)filemagic, DetectFilemagicThreadFree, 1);
+    if (g_magic_thread_ctx_id == -1)
+        goto error;
 
     /* Okay so far so good, lets get this into a SigMatch
      * and put it in the Signature. */