From: Victor Julien Date: Tue, 5 Apr 2016 11:14:03 +0000 (+0200) Subject: detect: fix error handling in mpm setup X-Git-Tag: suricata-3.1RC1~293 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d085362e610f1a64e08132d40890c791757c28e5;p=thirdparty%2Fsuricata.git detect: fix error handling in mpm setup *** 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) { --- diff --git a/src/detect-engine-mpm.c b/src/detect-engine-mpm.c index eb7edcbe54..39393e2bcb 100644 --- a/src/detect-engine-mpm.c +++ b/src/detect-engine-mpm.c @@ -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); } } }