From: Angelo Mirabella Date: Tue, 26 May 2020 17:00:06 +0000 (+0100) Subject: detect/magic: fix crash on rule reloading X-Git-Tag: suricata-5.0.5~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74221e9b549f3df250dc22eac2b8ba8a9a62004e;p=thirdparty%2Fsuricata.git detect/magic: fix crash on rule reloading 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) --- diff --git a/src/detect-filemagic.c b/src/detect-filemagic.c index 634b8e803a..3590c79787 100644 --- a/src/detect-filemagic.c +++ b/src/detect-filemagic.c @@ -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. */