mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 11:44:32 +03:00
Huge performance improvement: passing variables as pointers avoiding copies
This commit is contained in:
@@ -32,34 +32,33 @@ namespace actions {
|
||||
|
||||
bool Capture::evaluate(Rule *rule, Assay *assay) {
|
||||
operators::Operator *op = rule->op;
|
||||
std::list<std::string> match;
|
||||
std::list<std::string> *match;
|
||||
|
||||
operators::Pm *pm = dynamic_cast<operators::Pm *>(op);
|
||||
if (pm != NULL) {
|
||||
match = pm->matched;
|
||||
match = &pm->matched;
|
||||
}
|
||||
|
||||
operators::Rx *rx = dynamic_cast<operators::Rx *>(op);
|
||||
if (rx != NULL) {
|
||||
match = rx->matched;
|
||||
match = &rx->matched;
|
||||
}
|
||||
|
||||
operators::Contains *contains = dynamic_cast<operators::Contains *>(op);
|
||||
if (contains != NULL) {
|
||||
match = contains->matched;
|
||||
match = &contains->matched;
|
||||
}
|
||||
|
||||
if (match.empty()) {
|
||||
if (match->empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while (match.empty() == false) {
|
||||
assay->setCollection("TX", std::to_string(i), match.back());
|
||||
match.pop_back();
|
||||
while (match->empty() == false) {
|
||||
assay->setCollection("TX", std::to_string(i), match->back());
|
||||
match->pop_back();
|
||||
i++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -116,30 +116,29 @@ bool SetVar::evaluate(Rule *rule, Assay *assay) {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
int pre = 0;
|
||||
try {
|
||||
pre = stoi(predicate);
|
||||
} catch (...) {
|
||||
|
||||
std::string resolvedPre = MacroExpansion::expand(predicate, assay);
|
||||
if (operation == setOperation) {
|
||||
targetValue = resolvedPre;
|
||||
} else {
|
||||
int pre = 0;
|
||||
try {
|
||||
pre = stoi(MacroExpansion::expand(predicate, assay));
|
||||
pre = stoi(resolvedPre);
|
||||
} catch (...) {
|
||||
pre = 0;
|
||||
}
|
||||
}
|
||||
|
||||
switch (operation) {
|
||||
case setOperation:
|
||||
targetValue = MacroExpansion::expand(predicate, assay);
|
||||
break;
|
||||
case sumAndSetOperation:
|
||||
targetValue = std::to_string(value + pre);
|
||||
break;
|
||||
case substractAndSetOperation:
|
||||
targetValue = std::to_string(value - pre);
|
||||
break;
|
||||
case setToOne:
|
||||
targetValue = std::string("1");
|
||||
break;
|
||||
switch (operation) {
|
||||
case sumAndSetOperation:
|
||||
targetValue = std::to_string(value + pre);
|
||||
break;
|
||||
case substractAndSetOperation:
|
||||
targetValue = std::to_string(value - pre);
|
||||
break;
|
||||
case setToOne:
|
||||
targetValue = std::string("1");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NO_LOGS
|
||||
|
@@ -35,24 +35,18 @@ namespace transformations {
|
||||
|
||||
std::string RemoveNulls::evaluate(std::string value,
|
||||
Assay *assay) {
|
||||
int64_t i, j;
|
||||
int64_t i;
|
||||
|
||||
char *input = reinterpret_cast<char *>(malloc(value.size()
|
||||
* sizeof(char)));
|
||||
memcpy(input, value.c_str(), value.size());
|
||||
std::string ret;
|
||||
|
||||
i = j = 0;
|
||||
i = 0;
|
||||
while (i < value.size()) {
|
||||
if (input[i] != '\0') {
|
||||
input[j] = input[i];
|
||||
j++;
|
||||
if (value.at(i) != '\0') {
|
||||
ret += value.at(i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
std::string ret(input, 0, j);
|
||||
free(input);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user