]> 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)
committerVictor Julien <victor@inliniac.net>
Wed, 4 Nov 2020 15:30:24 +0000 (16:30 +0100)
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

src/detect-filemagic.c

index 3fc2d2858e56e2c8b7de36cfb7c6e1644fca14c6..536e88803f145503cba9e6f75a107f1dfb7838da 100644 (file)
@@ -361,13 +361,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. */