mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 13:56:01 +03:00
Removes memory leak on the "offset" feature
This commit is contained in:
parent
c1f11ab4e5
commit
17e5a63577
@ -40,12 +40,12 @@ class Variable {
|
|||||||
m_key(key),
|
m_key(key),
|
||||||
m_value(),
|
m_value(),
|
||||||
m_dynamic_value(false),
|
m_dynamic_value(false),
|
||||||
m_dynamic(false) { }
|
m_dynamic(true) { }
|
||||||
Variable(const std::string *key, const std::string *value) :
|
Variable(const std::string *key, const std::string *value) :
|
||||||
m_key(key),
|
m_key(key),
|
||||||
m_value(value),
|
m_value(value),
|
||||||
m_dynamic_value(false),
|
m_dynamic_value(false),
|
||||||
m_dynamic(false) { }
|
m_dynamic(true) { }
|
||||||
|
|
||||||
~Variable() {
|
~Variable() {
|
||||||
if (m_dynamic_value) {
|
if (m_dynamic_value) {
|
||||||
|
@ -87,28 +87,6 @@ class Operator;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VariableOriginRequest : public VariableOrigin {
|
|
||||||
public:
|
|
||||||
VariableOriginRequest()
|
|
||||||
: m_length(0),
|
|
||||||
m_offset(0) { }
|
|
||||||
|
|
||||||
std::string toText() {
|
|
||||||
#if 0
|
|
||||||
return "Variable origin was extracted straight from " \
|
|
||||||
"request/response, offset: " + std::to_string(m_offset) + \
|
|
||||||
", length: " + std::to_string(m_length) + ".";
|
|
||||||
#else
|
|
||||||
return "rr:" + std::to_string(m_offset) + "," \
|
|
||||||
+ std::to_string(m_length);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int m_length;
|
|
||||||
int m_offset;
|
|
||||||
};
|
|
||||||
|
|
||||||
class AnchoredVariable {
|
class AnchoredVariable {
|
||||||
public:
|
public:
|
||||||
AnchoredVariable(Transaction *t, std::string name)
|
AnchoredVariable(Transaction *t, std::string name)
|
||||||
@ -121,9 +99,14 @@ class AnchoredVariable {
|
|||||||
m_var->m_value = &m_value;
|
m_var->m_value = &m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~AnchoredVariable() {
|
||||||
|
delete (m_var);
|
||||||
|
m_var = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void set(const std::string &a, size_t offset) {
|
void set(const std::string &a, size_t offset) {
|
||||||
std::unique_ptr<VariableOriginRequest> origin(
|
std::unique_ptr<VariableOrigin> origin(
|
||||||
new VariableOriginRequest());
|
new VariableOrigin());
|
||||||
m_offset = offset;
|
m_offset = offset;
|
||||||
m_value.assign(a.c_str(), a.size());
|
m_value.assign(a.c_str(), a.size());
|
||||||
origin->m_offset = offset;
|
origin->m_offset = offset;
|
||||||
@ -133,8 +116,8 @@ class AnchoredVariable {
|
|||||||
|
|
||||||
void append(const std::string &a, size_t offset,
|
void append(const std::string &a, size_t offset,
|
||||||
bool spaceSeparator = false) {
|
bool spaceSeparator = false) {
|
||||||
std::unique_ptr<VariableOriginRequest> origin(
|
std::unique_ptr<VariableOrigin> origin(
|
||||||
new VariableOriginRequest());
|
new VariableOrigin());
|
||||||
if (spaceSeparator && !m_value.empty()) {
|
if (spaceSeparator && !m_value.empty()) {
|
||||||
m_value.append(" " + a);
|
m_value.append(" " + a);
|
||||||
} else {
|
} else {
|
||||||
@ -229,7 +212,8 @@ class TransactionAnchoredVariables {
|
|||||||
m_variableSessionID(t, "SESSIONID"),
|
m_variableSessionID(t, "SESSIONID"),
|
||||||
m_variableUniqueID(t, "UNIQUE_ID"),
|
m_variableUniqueID(t, "UNIQUE_ID"),
|
||||||
m_variableUrlEncodedError(t, "URLENCODED_ERROR"),
|
m_variableUrlEncodedError(t, "URLENCODED_ERROR"),
|
||||||
m_variableUserID(t, "USERID")
|
m_variableUserID(t, "USERID"),
|
||||||
|
m_variableOffset(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
AnchoredVariable m_variableArgsNames;
|
AnchoredVariable m_variableArgsNames;
|
||||||
|
@ -33,8 +33,18 @@ namespace modsecurity {
|
|||||||
/** @ingroup ModSecurity_CPP_API */
|
/** @ingroup ModSecurity_CPP_API */
|
||||||
class VariableOrigin {
|
class VariableOrigin {
|
||||||
public:
|
public:
|
||||||
VariableOrigin() { }
|
VariableOrigin()
|
||||||
virtual std::string toText() = 0;
|
: m_length(0),
|
||||||
|
m_offset(0) { }
|
||||||
|
|
||||||
|
std::string toText() {
|
||||||
|
std::string offset = std::to_string(m_offset);
|
||||||
|
std::string len = std::to_string(m_length);
|
||||||
|
return "rr:" + offset + "," + len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int m_length;
|
||||||
|
size_t m_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user