Fixed LMDB collection errors

This commit is contained in:
Ervin Hegedus
2018-05-28 21:00:14 +00:00
committed by Felipe Zimmerle
parent 1527f4e2f2
commit edb5993d5f
3 changed files with 38 additions and 21 deletions

View File

@@ -27,7 +27,6 @@
#undef LMDB_STDOUT_COUT #undef LMDB_STDOUT_COUT
namespace modsecurity { namespace modsecurity {
namespace collection { namespace collection {
namespace backend { namespace backend {
@@ -35,8 +34,8 @@ namespace backend {
#ifdef WITH_LMDB #ifdef WITH_LMDB
LMDB::LMDB(std::string name) :
LMDB::LMDB() : Collection(""), m_env(NULL) { Collection(name), m_env(NULL) {
mdb_env_create(&m_env); mdb_env_create(&m_env);
mdb_env_open(m_env, "./modsec-shared-collections", mdb_env_open(m_env, "./modsec-shared-collections",
MDB_WRITEMAP | MDB_NOSUBDIR, 0664); MDB_WRITEMAP | MDB_NOSUBDIR, 0664);
@@ -121,7 +120,7 @@ void LMDB::lmdb_debug(int rc, std::string op, std::string scope) {
} }
std::cout << std::endl; std::cout << std::endl;
} else if (op == "del") { } else if (op == "del") {
td::cout << scope << ", delete procedure failed: "; std::cout << scope << ", delete procedure failed: ";
switch (rc) { switch (rc) {
case EACCES: case EACCES:
std::cout << "an attempt was made to write in a "; std::cout << "an attempt was made to write in a ";
@@ -494,22 +493,40 @@ void LMDB::resolveMultiMatches(const std::string& var,
} }
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
if (key.mv_size <= keySize + 1) { //
continue; // I don't see what's the reason of this clause
} //
// eg:
// looking for the variable: 'test', keySize will 4
// found key: 'test', key.mv_size will 4
// key.mv_size IS LESS than keySize+1, so we will continue?
//
//if (key.mv_size <= keySize + 1) {
// continue;
//}
char *a = reinterpret_cast<char *>(key.mv_data); char *a = reinterpret_cast<char *>(key.mv_data);
if (a[keySize] != ':') { //
continue; // also don't understand this part
} //
// key.mv_data will 'test', but there isn't ':' at the end,
// so we will skip it?
//
//if (a[keySize] != ':') {
// continue;
//}
// this will never evaluate with the two statements above,
// but I think this is the only required check
if (strncmp(var.c_str(), a, keySize) != 0) { if (strncmp(var.c_str(), a, keySize) != 0) {
continue; continue;
} }
VariableValue *v = new VariableValue( l->insert(l->begin(), new VariableValue(
new std::string(reinterpret_cast<char *>(key.mv_data), &m_name,
new std::string(reinterpret_cast<char *>(key.mv_data),
key.mv_size), key.mv_size),
new std::string(reinterpret_cast<char *>(data.mv_data), new std::string(reinterpret_cast<char *>(data.mv_data),
data.mv_size)); data.mv_size))
l->insert(l->begin(), v); );
} }
mdb_cursor_close(cursor); mdb_cursor_close(cursor);

View File

@@ -50,7 +50,7 @@ namespace backend {
class LMDB : class LMDB :
public Collection { public Collection {
public: public:
LMDB(); LMDB(std::string name);
~LMDB(); ~LMDB();
void store(std::string key, std::string value) override; void store(std::string key, std::string value) override;

View File

@@ -63,11 +63,11 @@ ModSecurity::ModSecurity()
: m_connector(""), : m_connector(""),
m_whoami(""), m_whoami(""),
#ifdef WITH_LMDB #ifdef WITH_LMDB
m_global_collection(new collection::backend::LMDB()), m_global_collection(new collection::backend::LMDB("GLOBAL")),
m_resource_collection(new collection::backend::LMDB()), m_resource_collection(new collection::backend::LMDB("RESOURCE")),
m_ip_collection(new collection::backend::LMDB()), m_ip_collection(new collection::backend::LMDB("IP")),
m_session_collection(new collection::backend::LMDB()), m_session_collection(new collection::backend::LMDB("SESSION")),
m_user_collection(new collection::backend::LMDB()), m_user_collection(new collection::backend::LMDB("USER")),
#else #else
m_global_collection(new collection::backend::InMemoryPerProcess("GLOBAL")), m_global_collection(new collection::backend::InMemoryPerProcess("GLOBAL")),
m_ip_collection(new collection::backend::InMemoryPerProcess("IP")), m_ip_collection(new collection::backend::InMemoryPerProcess("IP")),