mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +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) {
|
||||
std::string targetValue;
|
||||
|
||||
variableName = MacroExpansion::expand(variableName, assay);
|
||||
int value = 0;
|
||||
try {
|
||||
std::string *resolvedValue =
|
||||
assay->resolve_variable_first(collectionName, variableName);
|
||||
if (resolvedValue == NULL) {
|
||||
value = 0;
|
||||
} else {
|
||||
value = stoi(*resolvedValue);
|
||||
}
|
||||
} catch (...) {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
|
||||
std::string variableNameExpanded = MacroExpansion::expand(variableName, assay);
|
||||
std::string resolvedPre = MacroExpansion::expand(predicate, assay);
|
||||
|
||||
if (operation == setOperation) {
|
||||
targetValue = resolvedPre;
|
||||
} else if (operation == setToOne) {
|
||||
targetValue = std::string("1");
|
||||
} else {
|
||||
int pre = 0;
|
||||
try {
|
||||
@ -128,6 +117,19 @@ bool SetVar::evaluate(Rule *rule, Assay *assay) {
|
||||
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) {
|
||||
case sumAndSetOperation:
|
||||
targetValue = std::to_string(value + pre);
|
||||
@ -135,17 +137,14 @@ bool SetVar::evaluate(Rule *rule, Assay *assay) {
|
||||
case substractAndSetOperation:
|
||||
targetValue = std::to_string(value - pre);
|
||||
break;
|
||||
case setToOne:
|
||||
targetValue = std::string("1");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NO_LOGS
|
||||
assay->debug(8, "Saving variable: " + collectionName + ":" + \
|
||||
variableName + " with value: " + targetValue);
|
||||
variableNameExpanded + " with value: " + targetValue);
|
||||
#endif
|
||||
assay->setCollection(collectionName, variableName, targetValue);
|
||||
assay->setCollection(collectionName, variableNameExpanded, targetValue);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user