From acc721c36c21386bbcd92a643018ef5df6d06e6a Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 31 Mar 2014 16:32:58 -0500 Subject: [PATCH] Fix mem leak and unchecked dynamic cast reported by Coverity. --- src/RuleMatcher.cc | 4 ++++ src/analyzer/protocol/file/File.cc | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index 65fbe5602d..5e9dff0a1f 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -686,6 +686,10 @@ RuleMatcher::MIME_Matches* RuleMatcher::Match(RuleFileMagicState* state, loop_over_list(r->actions, rai) { const RuleActionMIME* ram = dynamic_cast(r->actions[rai]); + + if ( ! ram ) + continue; + set& ss = (*rval)[ram->GetStrength()]; ss.insert(ram->GetMIME()); } diff --git a/src/analyzer/protocol/file/File.cc b/src/analyzer/protocol/file/File.cc index 7c471e17cf..4476043721 100644 --- a/src/analyzer/protocol/file/File.cc +++ b/src/analyzer/protocol/file/File.cc @@ -49,12 +49,9 @@ void File_Analyzer::Done() void File_Analyzer::Identify() { - RuleFileMagicState* fms = rule_matcher->InitFileMagic(); RuleMatcher::MIME_Matches matches; - - rule_matcher->Match(fms, reinterpret_cast(buffer), - buffer_len, &matches); - + file_mgr->DetectMIME(reinterpret_cast(buffer), buffer_len, + &matches); string match = matches.empty() ? "" : *(matches.begin()->second.begin()); val_list* vl = new val_list;