Makes operator to use string_view

This commit is contained in:
Felipe Zimmerle
2019-03-05 12:26:44 -03:00
parent d5158f1afc
commit 301f724e9e
85 changed files with 1954 additions and 298 deletions

View File

@@ -41,6 +41,7 @@
#include "src/actions/block.h"
#include "src/variables/variable.h"
#include "src/rule_with_operator.h"
#include "modsecurity/string_view.hpp"
namespace modsecurity {
@@ -68,8 +69,9 @@ RuleWithOperator::~RuleWithOperator() {
}
void RuleWithOperator::updateMatchedVars(Transaction *trans, const std::string &key,
const std::string &value) {
void RuleWithOperator::updateMatchedVars(Transaction *trans,
const std::string &key,
const bpstd::string_view &value) {
ms_dbg_a(trans, 9, "Matched vars updated.");
trans->m_variableMatchedVar.set(value, trans->m_variableOffset);
trans->m_variableMatchedVarName.set(key, trans->m_variableOffset);
@@ -88,9 +90,9 @@ void RuleWithOperator::cleanMatchedVars(Transaction *trans) {
}
bool RuleWithOperator::executeOperatorAt(Transaction *trans, const std::string &key,
std::string value) {
bool RuleWithOperator::executeOperatorAt(Transaction *trans,
const std::string &key,
const bpstd::string_view &value) {
#if MSC_EXEC_CLOCK_ENABLED
clock_t begin = clock();
clock_t end;
@@ -98,16 +100,13 @@ bool RuleWithOperator::executeOperatorAt(Transaction *trans, const std::string &
#endif
bool ret;
ms_dbg_a(trans, 9, "Target value: \"" + utils::string::limitTo(80,
utils::string::toHexIfNeeded(value)) \
ms_dbg_a(trans, 9, "Target value: \"" \
+ utils::string::limitTo(80,
utils::string::toHexIfNeeded(value.to_string())) \
+ "\" (Variable: " + key + ")");
ret = m_operator->evaluateInternal(trans, this, value, trans->messageGetLast());
if (ret == false) {
return false;
}
#if MSC_EXEC_CLOCK_ENABLED
end = clock();
elapsed_s = static_cast<double>(end - begin) / CLOCKS_PER_SEC;
@@ -302,10 +301,9 @@ bool RuleWithOperator::evaluate(Transaction *trans) {
while (iter != transformationsResults.end()) {
bool ret;
auto &valueTemp = *iter;
// FIXME: this copy is not necessary.
std::string *valueAfterTrans = new std::string(valueTemp.getAfter()->c_str(), valueTemp.getAfter()->size());
bpstd::string_view view = *valueTemp.getAfter();
ret = executeOperatorAt(trans, key, *valueAfterTrans);
ret = executeOperatorAt(trans, key, view);
if (ret == true) {
trans->messageGetLast()->m_match = m_operator->resolveMatchMessage(trans,
@@ -330,12 +328,12 @@ bool RuleWithOperator::evaluate(Transaction *trans) {
iter2++;
}
updateMatchedVars(trans, key, *valueAfterTrans);
updateMatchedVars(trans, key, view);
executeActionsIndependentOfChainedRuleResult(trans);
globalRet = true;
}
delete valueAfterTrans;
iter++;
}
delete v;