mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 03:34:29 +03:00
Fix memory issues while resolving variables
This commit is contained in:
@@ -42,14 +42,16 @@ void RemoteUser::evaluate(Transaction *transaction,
|
||||
size_t pos;
|
||||
std::string base64;
|
||||
collection::Variable *var;
|
||||
std::string header;
|
||||
|
||||
transaction->m_variableRequestHeaders.resolve("authorization", l);
|
||||
std::vector<const collection::Variable *> *l2 = new std::vector<const collection::Variable *>();
|
||||
transaction->m_variableRequestHeaders.resolve("authorization", l2);
|
||||
|
||||
if (l->size() < 1) {
|
||||
return;
|
||||
if (l2->size() < 1) {
|
||||
goto clear;
|
||||
}
|
||||
|
||||
std::string header(*l->at(0)->m_value);
|
||||
header = std::string(l2->at(0)->m_value);
|
||||
|
||||
if (header.compare(0, 6, "Basic ") == 0) {
|
||||
base64 = std::string(header, 6, header.length());
|
||||
@@ -59,22 +61,27 @@ void RemoteUser::evaluate(Transaction *transaction,
|
||||
|
||||
pos = base64.find(":");
|
||||
if (pos == std::string::npos) {
|
||||
return;
|
||||
goto clear;
|
||||
}
|
||||
transaction->m_variableRemoteUser.assign(std::string(base64, 0, pos));
|
||||
|
||||
var = new collection::Variable(l->at(0)->m_key,
|
||||
std::make_shared<std::string>(transaction->m_variableRemoteUser));
|
||||
var = new collection::Variable(&l2->at(0)->m_key,
|
||||
&transaction->m_variableRemoteUser);
|
||||
|
||||
for (auto &i : l->at(0)->m_orign) {
|
||||
for (auto &i : l2->at(0)->m_orign) {
|
||||
std::unique_ptr<VariableOrigin> origin(new VariableOrigin());
|
||||
origin->m_offset = i->m_offset;
|
||||
origin->m_length = i->m_length;
|
||||
var->m_orign.push_back(std::move(origin));
|
||||
}
|
||||
|
||||
l->clear();
|
||||
l->push_back(var);
|
||||
|
||||
clear:
|
||||
for (auto &a : *l2) {
|
||||
delete a;
|
||||
}
|
||||
l2->clear();
|
||||
delete l2;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -126,24 +126,22 @@ class VariableModificatorCount : public Variable {
|
||||
Rule *rule,
|
||||
std::vector<const collection::Variable *> *l) {
|
||||
std::vector<const collection::Variable *> reslIn;
|
||||
std::string *res = NULL;
|
||||
collection::Variable *val = NULL;
|
||||
int count = 0;
|
||||
|
||||
m_var->evaluate(transaction, rule, &reslIn);
|
||||
for (const collection::Variable *a : reslIn) {
|
||||
count++;
|
||||
if (a->m_dynamic) {
|
||||
delete a;
|
||||
a = NULL;
|
||||
}
|
||||
delete a;
|
||||
a = NULL;
|
||||
}
|
||||
reslIn.clear();
|
||||
|
||||
res = new std::string(std::to_string(count));
|
||||
|
||||
val = new collection::Variable(&m_name, res);
|
||||
val->m_dynamic = true;
|
||||
std::string *res = new std::string(std::to_string(count));
|
||||
std::string *name = new std::string(m_name);
|
||||
val = new collection::Variable(name, res);
|
||||
delete name;
|
||||
delete res;
|
||||
|
||||
l->push_back(val);
|
||||
return;
|
||||
|
@@ -125,8 +125,10 @@ void XML::evaluate(Transaction *t,
|
||||
content = reinterpret_cast<char *>(
|
||||
xmlNodeGetContent(nodes->nodeTab[i]));
|
||||
if (content != NULL) {
|
||||
std::string *a = new std::string(content);
|
||||
collection::Variable *var = new collection::Variable(&m_name,
|
||||
new std::string(content));
|
||||
a);
|
||||
delete a;
|
||||
l->push_back(var);
|
||||
xmlFree(content);
|
||||
}
|
||||
|
@@ -40,13 +40,12 @@ class XML_NoDictElement : public Variable {
|
||||
: Variable("XML"),
|
||||
m_plain("[XML document tree]"),
|
||||
m_var(&m_name, &m_plain) {
|
||||
m_var.m_dynamic = false;
|
||||
}
|
||||
|
||||
void evaluate(Transaction *transaction,
|
||||
Rule *rule,
|
||||
std::vector<const collection::Variable *> *l) override {
|
||||
l->push_back(&m_var);
|
||||
l->push_back(new collection::Variable(&m_var));
|
||||
}
|
||||
|
||||
std::string m_plain;
|
||||
|
Reference in New Issue
Block a user