mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-16 07:56:12 +03:00
Performance improvement of setVar action
This commit is contained in:
parent
e57ee8908f
commit
3351338551
@ -101,25 +101,14 @@ void SetVar::dump() {
|
|||||||
|
|
||||||
bool SetVar::evaluate(Rule *rule, Assay *assay) {
|
bool SetVar::evaluate(Rule *rule, Assay *assay) {
|
||||||
std::string targetValue;
|
std::string targetValue;
|
||||||
|
|
||||||
variableName = MacroExpansion::expand(variableName, assay);
|
|
||||||
int value = 0;
|
int value = 0;
|
||||||
try {
|
std::string variableNameExpanded = MacroExpansion::expand(variableName, assay);
|
||||||
std::string *resolvedValue =
|
|
||||||
assay->resolve_variable_first(collectionName, variableName);
|
|
||||||
if (resolvedValue == NULL) {
|
|
||||||
value = 0;
|
|
||||||
} else {
|
|
||||||
value = stoi(*resolvedValue);
|
|
||||||
}
|
|
||||||
} catch (...) {
|
|
||||||
value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::string resolvedPre = MacroExpansion::expand(predicate, assay);
|
std::string resolvedPre = MacroExpansion::expand(predicate, assay);
|
||||||
|
|
||||||
if (operation == setOperation) {
|
if (operation == setOperation) {
|
||||||
targetValue = resolvedPre;
|
targetValue = resolvedPre;
|
||||||
|
} else if (operation == setToOne) {
|
||||||
|
targetValue = std::string("1");
|
||||||
} else {
|
} else {
|
||||||
int pre = 0;
|
int pre = 0;
|
||||||
try {
|
try {
|
||||||
@ -128,6 +117,19 @@ bool SetVar::evaluate(Rule *rule, Assay *assay) {
|
|||||||
pre = 0;
|
pre = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::string *resolvedValue =
|
||||||
|
assay->resolve_variable_first(collectionName,
|
||||||
|
variableNameExpanded);
|
||||||
|
if (resolvedValue == NULL) {
|
||||||
|
value = 0;
|
||||||
|
} else {
|
||||||
|
value = stoi(*resolvedValue);
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case sumAndSetOperation:
|
case sumAndSetOperation:
|
||||||
targetValue = std::to_string(value + pre);
|
targetValue = std::to_string(value + pre);
|
||||||
@ -135,17 +137,14 @@ bool SetVar::evaluate(Rule *rule, Assay *assay) {
|
|||||||
case substractAndSetOperation:
|
case substractAndSetOperation:
|
||||||
targetValue = std::to_string(value - pre);
|
targetValue = std::to_string(value - pre);
|
||||||
break;
|
break;
|
||||||
case setToOne:
|
|
||||||
targetValue = std::string("1");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
assay->debug(8, "Saving variable: " + collectionName + ":" + \
|
assay->debug(8, "Saving variable: " + collectionName + ":" + \
|
||||||
variableName + " with value: " + targetValue);
|
variableNameExpanded + " with value: " + targetValue);
|
||||||
#endif
|
#endif
|
||||||
assay->setCollection(collectionName, variableName, targetValue);
|
assay->setCollection(collectionName, variableNameExpanded, targetValue);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user