mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 03:34:29 +03:00
Extends the direct access model to other collections
This commit is contained in:
committed by
Felipe Zimmerle
parent
ca24b6bb06
commit
f2d149fc5f
@@ -155,11 +155,11 @@ void InMemoryPerProcess::resolveRegularExpression(const std::string& var,
|
||||
}
|
||||
|
||||
|
||||
std::string* InMemoryPerProcess::resolveFirst(const std::string& var) {
|
||||
std::unique_ptr<std::string> InMemoryPerProcess::resolveFirst(const std::string& var) {
|
||||
auto range = equal_range(var);
|
||||
|
||||
for (auto it = range.first; it != range.second; ++it) {
|
||||
return &it->second;
|
||||
return std::unique_ptr<std::string>(new std::string(it->second));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@@ -82,7 +82,7 @@ class InMemoryPerProcess :
|
||||
|
||||
void del(const std::string& key) override;
|
||||
|
||||
std::string* resolveFirst(const std::string& var) override;
|
||||
std::unique_ptr<std::string> resolveFirst(const std::string& var) override;
|
||||
|
||||
void resolveSingleMatch(const std::string& var,
|
||||
std::vector<const Variable *> *l) override;
|
||||
|
@@ -161,7 +161,7 @@ void LMDB::lmdb_debug(int rc, std::string op, std::string scope) {
|
||||
}
|
||||
|
||||
|
||||
std::string* LMDB::resolveFirst(const std::string& var) {
|
||||
std::unique_ptr<std::string> LMDB::resolveFirst(const std::string& var) {
|
||||
int rc;
|
||||
MDB_val mdb_key;
|
||||
MDB_val mdb_value;
|
||||
@@ -188,10 +188,9 @@ std::string* LMDB::resolveFirst(const std::string& var) {
|
||||
goto end_get;
|
||||
}
|
||||
|
||||
// FIXME: Memory leak here.
|
||||
ret = new std::string(
|
||||
ret = std::unique_ptr<std::string>(new std::string(
|
||||
reinterpret_cast<char *>(mdb_value_ret.mv_data),
|
||||
mdb_value_ret.mv_size);
|
||||
mdb_value_ret.mv_size));
|
||||
|
||||
end_get:
|
||||
mdb_dbi_close(m_env, dbi);
|
||||
|
@@ -61,7 +61,7 @@ class LMDB :
|
||||
|
||||
void del(const std::string& key) override;
|
||||
|
||||
std::string* resolveFirst(const std::string& var) override;
|
||||
std::unique_ptr<std::string> resolveFirst(const std::string& var) override;
|
||||
|
||||
void resolveSingleMatch(const std::string& var,
|
||||
std::vector<const Variable *> *l) override;
|
||||
|
@@ -125,26 +125,27 @@ void Collections::del(const std::string& key) {
|
||||
}
|
||||
|
||||
|
||||
std::string* Collections::resolveFirst(const std::string& var) {
|
||||
std::string *transientVar = m_transient->resolveFirst(var);
|
||||
std::unique_ptr<std::string> Collections::resolveFirst(const std::string& var) {
|
||||
std::unique_ptr<std::string> transientVar = m_transient->resolveFirst(var);
|
||||
|
||||
if (transientVar != NULL) {
|
||||
return transientVar;
|
||||
}
|
||||
|
||||
for (auto &a : *this) {
|
||||
std::string *res = a.second->resolveFirst(
|
||||
std::unique_ptr<std::string> res = a.second->resolveFirst(
|
||||
utils::string::toupper(a.first) + ":" + var);
|
||||
|
||||
if (res != NULL) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
std::string* Collections::resolveFirst(const std::string& collectionName,
|
||||
std::unique_ptr<std::string> Collections::resolveFirst(const std::string& collectionName,
|
||||
const std::string& var) {
|
||||
if (utils::string::tolower(collectionName) == "ip"
|
||||
&& !m_ip_collection_key.empty()) {
|
||||
@@ -177,7 +178,7 @@ std::string* Collections::resolveFirst(const std::string& collectionName,
|
||||
for (auto &a : *this) {
|
||||
if (utils::string::tolower(a.first)
|
||||
== utils::string::tolower(collectionName)) {
|
||||
std::string *res = a.second->resolveFirst(
|
||||
std::unique_ptr<std::string> res = a.second->resolveFirst(
|
||||
utils::string::toupper(a.first)
|
||||
+ ":" + var);
|
||||
if (res != NULL) {
|
||||
|
Reference in New Issue
Block a user