]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: fix error handling in mpm setup
authorVictor Julien <victor@inliniac.net>
Tue, 5 Apr 2016 11:14:03 +0000 (13:14 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 5 Apr 2016 11:14:03 +0000 (13:14 +0200)
*** CID 1358124:  Null pointer dereferences  (REVERSE_INULL)
/src/detect-engine-mpm.c: 940 in MpmStoreSetup()
934                     PopulateMpmHelperAddPatternToPktCtx(ms->mpm_ctx,
935                             cd, s, 0, (cd->flags & DETECT_CONTENT_FAST_PATTERN_CHOP));
936                 }
937             }
938         }
939
>>>     CID 1358124:  Null pointer dereferences  (REVERSE_INULL)
>>>     Null-checking "ms->mpm_ctx" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
940         if (ms->mpm_ctx != NULL) {
941             if (ms->mpm_ctx->pattern_cnt == 0) {
942                 MpmFactoryReClaimMpmCtx(de_ctx, ms->mpm_ctx);
943                 ms->mpm_ctx = NULL;
944             } else {
945                 if (ms->sgh_mpm_context == MPM_CTX_FACTORY_UNIQUE_CONTEXT) {

src/detect-engine-mpm.c

index eb7edcbe54b513b28c8d38065e38c70e96a0eccd..39393e2bcbd959876833cf6d7f407b746a096a8b 100644 (file)
@@ -895,6 +895,9 @@ void MpmStoreSetup(const DetectEngineCtx *de_ctx, MpmStore *ms)
     }
 
     ms->mpm_ctx = MpmFactoryGetMpmCtxForProfile(de_ctx, ms->sgh_mpm_context, dir);
+    if (ms->mpm_ctx == NULL)
+        return;
+
     MpmInitCtx(ms->mpm_ctx, de_ctx->mpm_matcher);
 
     /* add the patterns */
@@ -937,15 +940,13 @@ void MpmStoreSetup(const DetectEngineCtx *de_ctx, MpmStore *ms)
         }
     }
 
-    if (ms->mpm_ctx != NULL) {
-        if (ms->mpm_ctx->pattern_cnt == 0) {
-            MpmFactoryReClaimMpmCtx(de_ctx, ms->mpm_ctx);
-            ms->mpm_ctx = NULL;
-        } else {
-            if (ms->sgh_mpm_context == MPM_CTX_FACTORY_UNIQUE_CONTEXT) {
-                if (mpm_table[ms->mpm_ctx->mpm_type].Prepare != NULL) {
-                    mpm_table[ms->mpm_ctx->mpm_type].Prepare(ms->mpm_ctx);
-                }
+    if (ms->mpm_ctx->pattern_cnt == 0) {
+        MpmFactoryReClaimMpmCtx(de_ctx, ms->mpm_ctx);
+        ms->mpm_ctx = NULL;
+    } else {
+        if (ms->sgh_mpm_context == MPM_CTX_FACTORY_UNIQUE_CONTEXT) {
+            if (mpm_table[ms->mpm_ctx->mpm_type].Prepare != NULL) {
+                mpm_table[ms->mpm_ctx->mpm_type].Prepare(ms->mpm_ctx);
             }
         }
     }