From 778db259cfbcc67d9e702d4693497fca029da354 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Thu, 18 Feb 2016 19:58:14 -0300 Subject: [PATCH] Treats the keys of the sec language variables as case-insensitive --- headers/modsecurity/transaction/variables.h | 43 ++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/headers/modsecurity/transaction/variables.h b/headers/modsecurity/transaction/variables.h index d2c3e995..21414b88 100644 --- a/headers/modsecurity/transaction/variables.h +++ b/headers/modsecurity/transaction/variables.h @@ -20,6 +20,7 @@ #include #include #include +#include #endif @@ -36,8 +37,47 @@ typedef struct Variable_t Variables; namespace modsecurity { namespace transaction { + +/* + * FIXME: + * + * This was an example grabbed from: + * http://stackoverflow.com/questions/8627698/case-insensitive-stl-containers-e-g-stdunordered-set + * + * We have to have a better hash function, maybe based on the std::hash. + * + */ +struct MyEqual +{ + bool operator()(const std::string& Left, const std::string& Right) const + { + return Left.size() == Right.size() + && std::equal ( Left.begin() , Left.end() , Right.begin(), + []( char a , char b ) + { + return tolower(a) == tolower(b); + } + ); + } +}; + +struct MyHash +{ + size_t operator()(const std::string& Keyval) const + { + //You might need a better hash function than this + size_t h = 0; + std::for_each( Keyval.begin() , Keyval.end() , [&](char c ) + { + h += tolower(c); + }); + return h; + } +}; + class Variables : - public std::unordered_multimap { + public std::unordered_multimap*/MyHash, MyEqual> { public: Variables(); ~Variables(); @@ -59,6 +99,7 @@ class Variables : std::vector *l); void resolveRegularExpression(const std::string& var, std::vector *l); + }; } // namespace transaction