Skip to content

Commit edb5993

Browse files
airweenFelipe Zimmerle
authored andcommitted
Fixed LMDB collection errors
1 parent 1527f4e commit edb5993

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

src/collection/backend/lmdb.cc

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@
2727

2828
#undef LMDB_STDOUT_COUT
2929

30-
3130
namespace modsecurity {
3231
namespace collection {
3332
namespace backend {
3433

3534

3635
#ifdef WITH_LMDB
3736

38-
39-
LMDB::LMDB() : Collection(""), m_env(NULL) {
37+
LMDB::LMDB(std::string name) :
38+
Collection(name), m_env(NULL) {
4039
mdb_env_create(&m_env);
4140
mdb_env_open(m_env, "./modsec-shared-collections",
4241
MDB_WRITEMAP | MDB_NOSUBDIR, 0664);
@@ -121,7 +120,7 @@ void LMDB::lmdb_debug(int rc, std::string op, std::string scope) {
121120
}
122121
std::cout << std::endl;
123122
} else if (op == "del") {
124-
td::cout << scope << ", delete procedure failed: ";
123+
std::cout << scope << ", delete procedure failed: ";
125124
switch (rc) {
126125
case EACCES:
127126
std::cout << "an attempt was made to write in a ";
@@ -494,22 +493,40 @@ void LMDB::resolveMultiMatches(const std::string& var,
494493
}
495494

496495
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
497-
if (key.mv_size <= keySize + 1) {
498-
continue;
499-
}
496+
//
497+
// I don't see what's the reason of this clause
498+
//
499+
// eg:
500+
// looking for the variable: 'test', keySize will 4
501+
// found key: 'test', key.mv_size will 4
502+
// key.mv_size IS LESS than keySize+1, so we will continue?
503+
//
504+
//if (key.mv_size <= keySize + 1) {
505+
// continue;
506+
//}
500507
char *a = reinterpret_cast<char *>(key.mv_data);
501-
if (a[keySize] != ':') {
502-
continue;
503-
}
508+
//
509+
// also don't understand this part
510+
//
511+
// key.mv_data will 'test', but there isn't ':' at the end,
512+
// so we will skip it?
513+
//
514+
//if (a[keySize] != ':') {
515+
// continue;
516+
//}
517+
518+
// this will never evaluate with the two statements above,
519+
// but I think this is the only required check
504520
if (strncmp(var.c_str(), a, keySize) != 0) {
505521
continue;
506522
}
507-
VariableValue *v = new VariableValue(
508-
new std::string(reinterpret_cast<char *>(key.mv_data),
523+
l->insert(l->begin(), new VariableValue(
524+
&m_name,
525+
new std::string(reinterpret_cast<char *>(key.mv_data),
509526
key.mv_size),
510-
new std::string(reinterpret_cast<char *>(data.mv_data),
511-
data.mv_size));
512-
l->insert(l->begin(), v);
527+
new std::string(reinterpret_cast<char *>(data.mv_data),
528+
data.mv_size))
529+
);
513530
}
514531

515532
mdb_cursor_close(cursor);

src/collection/backend/lmdb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace backend {
5050
class LMDB :
5151
public Collection {
5252
public:
53-
LMDB();
53+
LMDB(std::string name);
5454
~LMDB();
5555
void store(std::string key, std::string value) override;
5656

src/modsecurity.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ ModSecurity::ModSecurity()
6363
: m_connector(""),
6464
m_whoami(""),
6565
#ifdef WITH_LMDB
66-
m_global_collection(new collection::backend::LMDB()),
67-
m_resource_collection(new collection::backend::LMDB()),
68-
m_ip_collection(new collection::backend::LMDB()),
69-
m_session_collection(new collection::backend::LMDB()),
70-
m_user_collection(new collection::backend::LMDB()),
66+
m_global_collection(new collection::backend::LMDB("GLOBAL")),
67+
m_resource_collection(new collection::backend::LMDB("RESOURCE")),
68+
m_ip_collection(new collection::backend::LMDB("IP")),
69+
m_session_collection(new collection::backend::LMDB("SESSION")),
70+
m_user_collection(new collection::backend::LMDB("USER")),
7171
#else
7272
m_global_collection(new collection::backend::InMemoryPerProcess("GLOBAL")),
7373
m_ip_collection(new collection::backend::InMemoryPerProcess("IP")),

0 commit comments

Comments
 (0)