From f423c7bad94250a28e70ccb854eb67fd82df2da6 Mon Sep 17 00:00:00 2001 From: "Russ Combs (rucombs)" Date: Tue, 24 May 2016 14:58:41 -0400 Subject: [PATCH] Merge pull request #489 in SNORT/snort3 from ~MIALTIZE/snort3:snort2lua to master Squashed commit of the following: commit 5c2f5c73a956b4da8513e32bfb72dbdafdedd56e Author: Michael Altizer Date: Tue May 24 18:42:42 2016 +0000 snort2lua: Allow for case-insensitive preprocessor keyword matching --- tools/snort2lua/helpers/s2l_util.cc | 34 +++++++++++++++---- tools/snort2lua/helpers/s2l_util.h | 4 +-- .../keyword_states/kws_preprocessor.cc | 2 +- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/tools/snort2lua/helpers/s2l_util.cc b/tools/snort2lua/helpers/s2l_util.cc index dc263faa9..838fa33f3 100644 --- a/tools/snort2lua/helpers/s2l_util.cc +++ b/tools/snort2lua/helpers/s2l_util.cc @@ -51,22 +51,44 @@ std::vector& split(const std::string& s, const ConvertMap* find_map( const std::vector& map, - const std::string& keyword) + const std::string& keyword, + bool strict_case) { for (const ConvertMap* p : map) - if (p->keyword.compare(0, p->keyword.size(), keyword) == 0) - return p; + { + if (strict_case) + { + if (p->keyword.compare(0, p->keyword.size(), keyword) == 0) + return p; + } + else + { + if (case_compare(p->keyword, keyword)) + return p; + } + } return nullptr; } const std::unique_ptr& find_map( const std::vector >& map, - const std::string& keyword) + const std::string& keyword, + bool strict_case) { for (auto& p : map) - if (p->keyword.compare(0, p->keyword.size(), keyword) == 0) - return p; + { + if (strict_case) + { + if (p->keyword.compare(0, p->keyword.size(), keyword) == 0) + return p; + } + else + { + if (case_compare(p->keyword, keyword)) + return p; + } + } static std::unique_ptr np(nullptr); return np; diff --git a/tools/snort2lua/helpers/s2l_util.h b/tools/snort2lua/helpers/s2l_util.h index 0e8ed20c0..242e91959 100644 --- a/tools/snort2lua/helpers/s2l_util.h +++ b/tools/snort2lua/helpers/s2l_util.h @@ -39,9 +39,9 @@ std::vector& split(const std::string& s, char delim, std::vector& vec, const std::string& name); -const ConvertMap* find_map(const std::vector&, const std::string& keyword); +const ConvertMap* find_map(const std::vector&, const std::string& keyword, bool strict_case = true); const std::unique_ptr& find_map( - const std::vector >&, const std::string& keyword); + const std::vector >&, const std::string& keyword, bool strict_case = true); // trim from begining std::string& ltrim(std::string& s); diff --git a/tools/snort2lua/keyword_states/kws_preprocessor.cc b/tools/snort2lua/keyword_states/kws_preprocessor.cc index 9abb75f25..262efa162 100644 --- a/tools/snort2lua/keyword_states/kws_preprocessor.cc +++ b/tools/snort2lua/keyword_states/kws_preprocessor.cc @@ -44,7 +44,7 @@ bool Preprocessor::convert(std::istringstream& data_stream) if (util::get_string(data_stream, keyword, ":")) { - const ConvertMap* map = util::find_map(preprocessors::preprocessor_api, keyword); + const ConvertMap* map = util::find_map(preprocessors::preprocessor_api, keyword, false); if (map) { cv.set_state(map->ctor(cv)); -- 2.47.3