Skip to content
13 changes: 13 additions & 0 deletions headers/modsecurity/anchored_set_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,26 @@ class AnchoredSetVariable : public std::unordered_multimap<std::string,

void setCopy(std::string key, std::string value, size_t offset);

void resolve(std::vector<const VariableValue *> *l) const;
void resolve(std::vector<const VariableValue *> *l,
const variables::KeyExclusions &ke) const;

// keep the old signatures for ABI compatibility
void resolve(std::vector<const VariableValue *> *l);
void resolve(std::vector<const VariableValue *> *l,
variables::KeyExclusions &ke);

void resolve(const std::string &key,
std::vector<const VariableValue *> *l);

void resolveRegularExpression(Utils::Regex *r,
std::vector<const VariableValue *> *l) const;

void resolveRegularExpression(Utils::Regex *r,
std::vector<const VariableValue *> *l,
const variables::KeyExclusions &ke) const;

// keep the old signatures for ABI compatibility
void resolveRegularExpression(Utils::Regex *r,
std::vector<const VariableValue *> *l);

Expand Down
1 change: 1 addition & 0 deletions headers/modsecurity/audit_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class AuditLog {

bool saveIfRelevant(Transaction *transaction);
bool saveIfRelevant(Transaction *transaction, int parts);
bool isRelevant(int status) const;
bool isRelevant(int status);

static int addParts(int parts, std::string_view new_parts);
Expand Down
1 change: 1 addition & 0 deletions headers/modsecurity/rules_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class RulesSet : public RulesSetProperties {
int merge(RulesSet *rules);

int evaluate(int phase, Transaction *transaction);
std::string getParserError() const;
std::string getParserError();

void debug(int level, const std::string &id, const std::string &uri,
Expand Down
7 changes: 5 additions & 2 deletions src/actions/transformations/url_decode_uni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static inline bool inplace(std::string &value,
const auto input_len = value.length();

std::string::size_type i, count, fact, j, xv;
int Code, hmap = -1;
int hmap = -1;

i = count = 0;
while (i < input_len) {
Expand All @@ -50,13 +50,16 @@ static inline bool inplace(std::string &value,
(VALID_HEX(input[i + 3])) &&
(VALID_HEX(input[i + 4])) &&
(VALID_HEX(input[i + 5]))) {
Code = 0;

fact = 1;

if (t
&& t->m_rules->m_unicodeMapTable.m_set == true
&& t->m_rules->m_unicodeMapTable.m_unicodeMapTable != NULL
&& t->m_rules->m_unicodeMapTable.m_unicodeCodePage > 0) {

int Code = 0;

for (j = 5; j >= 2; j--) {
if (isxdigit((input[i+j]))) {
if (input[i+j] >= 97) {
Expand Down
34 changes: 30 additions & 4 deletions src/anchored_set_variable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,22 @@


void AnchoredSetVariable::resolve(
std::vector<const VariableValue *> *l) {
std::vector<const VariableValue *> *l) const {
for (const auto& x : *this) {
l->insert(l->begin(), new VariableValue(x.second));
}
}


void AnchoredSetVariable::resolve(
std::vector<const VariableValue *> *l) {
static_cast<const AnchoredSetVariable&>(*this).resolve(l);
}


void AnchoredSetVariable::resolve(
std::vector<const VariableValue *> *l,
variables::KeyExclusions &ke) {
const variables::KeyExclusions &ke) const {
for (const auto& x : *this) {
if (!ke.toOmit(x.first)) {
l->insert(l->begin(), new VariableValue(x.second));
Expand All @@ -88,6 +94,13 @@
}


void AnchoredSetVariable::resolve(
std::vector<const VariableValue *> *l,
variables::KeyExclusions &ke) { // cppcheck-suppress constParameterReference
static_cast<const AnchoredSetVariable&>(*this).resolve(l, ke);
}


void AnchoredSetVariable::resolve(const std::string &key,
std::vector<const VariableValue *> *l) {
auto range = this->equal_range(key);
Expand All @@ -109,7 +122,7 @@


void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
std::vector<const VariableValue *> *l) {
std::vector<const VariableValue *> *l) const {
for (const auto& x : *this) {
int ret = Utils::regex_search(x.first, *r);
if (ret <= 0) {
Expand All @@ -120,9 +133,15 @@
}


void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
std::vector<const VariableValue *> *l) {
static_cast<const AnchoredSetVariable&>(*this).resolveRegularExpression(r, l);
}


void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
std::vector<const VariableValue *> *l,
variables::KeyExclusions &ke) {
const variables::KeyExclusions &ke) const {
for (const auto& x : *this) {
int ret = Utils::regex_search(x.first, *r);
if (ret <= 0) {
Expand All @@ -138,4 +157,11 @@
}


void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
std::vector<const VariableValue *> *l,
variables::KeyExclusions &ke) { // cppcheck-suppress constParameterReference

Check warning on line 162 in src/anchored_set_variable.cc

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a reference-to-const. The current type of "ke" is "class modsecurity::variables::KeyExclusions &".

See more on https://sonarcloud.io/project/issues?id=owasp-modsecurity_ModSecurity&issues=AZzZvTxwL9JaeNKYlrGJ&open=AZzZvTxwL9JaeNKYlrGJ&pullRequest=3508
static_cast<const AnchoredSetVariable&>(*this).resolveRegularExpression(r, l, ke);
}


} // namespace modsecurity
6 changes: 5 additions & 1 deletion src/audit_log/audit_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ bool AuditLog::init(std::string *error) {
}


bool AuditLog::isRelevant(int status) {
bool AuditLog::isRelevant(int status) const {
std::string sstatus = std::to_string(status);

if (m_relevant.empty()) {
Expand All @@ -264,6 +264,10 @@ bool AuditLog::isRelevant(int status) {
Utils::Regex(m_relevant)) != 0;
}

bool AuditLog::isRelevant(int status) {
return static_cast<const AuditLog&>(*this).isRelevant(status);
}


bool AuditLog::saveIfRelevant(Transaction *transaction) {
return saveIfRelevant(transaction, -1);
Expand Down
8 changes: 6 additions & 2 deletions src/rules_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ int RulesSet::load(const char *plainRules) {
}


std::string RulesSet::getParserError() {
std::string RulesSet::getParserError() const {
return this->m_parserError.str();
}

std::string RulesSet::getParserError() {
return static_cast<const RulesSet&>(*this).getParserError();
}

void RulesSet::cleanMatchedVars(Transaction *trans) {
ms_dbg_a(trans, 9, "Matched vars cleaned.");
// cppcheck-suppress ctunullpointer
Expand All @@ -119,7 +123,7 @@ int RulesSet::evaluate(int phase, Transaction *t) {
return 0;
}

Rules *rules = m_rulesSetPhases[phase];
const Rules *rules = m_rulesSetPhases[phase];

ms_dbg_a(t, 9, "This phase consists of " \
+ std::to_string(rules->size()) + " rule(s).");
Expand Down
3 changes: 1 addition & 2 deletions src/rules_set_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ void ConfigUnicodeMap::loadConfig(std::string f, double configCodePage,
char *hmap = NULL;
const char *p = NULL;
char *savedptr = NULL;
const char *ucode = NULL;
int found = 0;
int length = 0;
int processing = 0;
Expand Down Expand Up @@ -99,7 +98,7 @@ void ConfigUnicodeMap::loadConfig(std::string f, double configCodePage,
processing = 1;

if (mapping != NULL) {
ucode = strtok_r(mapping, ":", &hmap);
const char *ucode = strtok_r(mapping, ":", &hmap);
int code = strtol(ucode, nullptr, 16);
int map = strtol(hmap, nullptr, 16);
if (code >= 0 && code <= 65535) {
Expand Down
2 changes: 1 addition & 1 deletion src/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ int Transaction::addRequestHeader(const std::string& key,

// find the first '='
pos = c.find_first_of("=", 0);
std::string ckey = "";
std::string ckey;
std::string cval = "";

// if the cookie doesn't contains '=', its just a key
Expand Down
2 changes: 1 addition & 1 deletion src/unique_id.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ std::string UniqueId::ethernetMacAddress() {

return std::string(reinterpret_cast<const char *>(mac));
#if defined(__linux__) || defined(__gnu_linux__) || defined(DARWIN) || defined(WIN32)
failed:
failed: // cppcheck-suppress unusedLabelConfiguration
return std::string("");
#endif
}
Expand Down
6 changes: 5 additions & 1 deletion src/variables/variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,18 @@ class KeyExclusions : public std::deque<std::unique_ptr<KeyExclusion>> {
KeyExclusions() {
}

bool toOmit(std::string a) {
bool toOmit(std::string a) const {
for (auto &z : *this) {
if (z->match(a)) {
return true;
}
}
return false;
}

bool toOmit(std::string a) { // cppcheck-suppress passedByValue
return static_cast<const KeyExclusions&>(*this).toOmit(a);
}
};


Expand Down
2 changes: 1 addition & 1 deletion test/fuzzer/afl_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int main(int argc, char** argv) {
read_bytes = read(STDIN_FILENO, buf, 128);

std::string currentString = std::string(read_bytes, 128);
std::string s = currentString;
const std::string& s = currentString;
#if 0
std::string z = lastString;
#endif
Expand Down
Loading