Skip to content

Commit 778db25

Browse files
author
Felipe Zimmerle
committed
Treats the keys of the sec language variables as case-insensitive
1 parent 30d9ade commit 778db25

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

headers/modsecurity/transaction/variables.h

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <unordered_map>
2121
#include <list>
2222
#include <vector>
23+
#include <algorithm>
2324
#endif
2425

2526

@@ -36,8 +37,47 @@ typedef struct Variable_t Variables;
3637
namespace modsecurity {
3738
namespace transaction {
3839

40+
41+
/*
42+
* FIXME:
43+
*
44+
* This was an example grabbed from:
45+
* http://stackoverflow.com/questions/8627698/case-insensitive-stl-containers-e-g-stdunordered-set
46+
*
47+
* We have to have a better hash function, maybe based on the std::hash.
48+
*
49+
*/
50+
struct MyEqual
51+
{
52+
bool operator()(const std::string& Left, const std::string& Right) const
53+
{
54+
return Left.size() == Right.size()
55+
&& std::equal ( Left.begin() , Left.end() , Right.begin(),
56+
[]( char a , char b )
57+
{
58+
return tolower(a) == tolower(b);
59+
}
60+
);
61+
}
62+
};
63+
64+
struct MyHash
65+
{
66+
size_t operator()(const std::string& Keyval) const
67+
{
68+
//You might need a better hash function than this
69+
size_t h = 0;
70+
std::for_each( Keyval.begin() , Keyval.end() , [&](char c )
71+
{
72+
h += tolower(c);
73+
});
74+
return h;
75+
}
76+
};
77+
3978
class Variables :
40-
public std::unordered_multimap<std::string, std::string> {
79+
public std::unordered_multimap<std::string, std::string,
80+
/*std::hash<std::string>*/MyHash, MyEqual> {
4181
public:
4282
Variables();
4383
~Variables();
@@ -59,6 +99,7 @@ class Variables :
5999
std::vector<const transaction::Variable *> *l);
60100
void resolveRegularExpression(const std::string& var,
61101
std::vector<const transaction::Variable *> *l);
102+
62103
};
63104

64105
} // namespace transaction

0 commit comments

Comments
 (0)