mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
cppcheck: make static analysis more pedantic
This commit is contained in:
@@ -37,36 +37,36 @@ bool ContainsWord::acceptableChar(const std::string& a, size_t pos) {
|
||||
}
|
||||
|
||||
bool ContainsWord::evaluate(Transaction *transaction, Rule *rule,
|
||||
const std::string &input, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||
const std::string &str, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||
std::string paramTarget(m_string->evaluate(transaction));
|
||||
|
||||
if (paramTarget.empty()) {
|
||||
return true;
|
||||
}
|
||||
if (input.empty()) {
|
||||
if (str.empty()) {
|
||||
return false;
|
||||
}
|
||||
if (input == paramTarget) {
|
||||
if (str == paramTarget) {
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t pos = input.find(paramTarget);
|
||||
size_t pos = str.find(paramTarget);
|
||||
while (pos != std::string::npos) {
|
||||
if (pos == 0 && acceptableChar(input, paramTarget.size())) {
|
||||
if (pos == 0 && acceptableChar(str, paramTarget.size())) {
|
||||
logOffset(ruleMessage, 0, paramTarget.size());
|
||||
return true;
|
||||
}
|
||||
if (pos + paramTarget.size() == input.size() &&
|
||||
acceptableChar(input, pos - 1)) {
|
||||
if (pos + paramTarget.size() == str.size() &&
|
||||
acceptableChar(str, pos - 1)) {
|
||||
logOffset(ruleMessage, pos, paramTarget.size());
|
||||
return true;
|
||||
}
|
||||
if (acceptableChar(input, pos - 1) &&
|
||||
acceptableChar(input, pos + paramTarget.size())) {
|
||||
if (acceptableChar(str, pos - 1) &&
|
||||
acceptableChar(str, pos + paramTarget.size())) {
|
||||
logOffset(ruleMessage, pos, paramTarget.size());
|
||||
return true;
|
||||
}
|
||||
pos = input.find(paramTarget, pos + 1);
|
||||
pos = str.find(paramTarget, pos + 1);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@@ -24,15 +24,15 @@ namespace operators {
|
||||
|
||||
|
||||
bool EndsWith::evaluate(Transaction *transaction, Rule *rule,
|
||||
const std::string &input, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||
const std::string &str, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||
bool ret = false;
|
||||
std::string p(m_string->evaluate(transaction));
|
||||
|
||||
if (input.length() >= p.length()) {
|
||||
ret = (0 == input.compare(input.length() - p.length(),
|
||||
if (str.length() >= p.length()) {
|
||||
ret = (0 == str.compare(str.length() - p.length(),
|
||||
p.length(), p));
|
||||
if (ret) {
|
||||
logOffset(ruleMessage, input.length() - p.length(),
|
||||
logOffset(ruleMessage, str.length() - p.length(),
|
||||
p.size());
|
||||
}
|
||||
}
|
||||
|
@@ -40,8 +40,8 @@ class FuzzyHash : public Operator {
|
||||
/** @ingroup ModSecurity_Operator */
|
||||
explicit FuzzyHash(std::unique_ptr<RunTimeString> param)
|
||||
: Operator("FuzzyHash", std::move(param)),
|
||||
m_head(NULL),
|
||||
m_threshold(0) { }
|
||||
m_threshold(0),
|
||||
m_head(NULL) { }
|
||||
~FuzzyHash();
|
||||
|
||||
bool evaluate(Transaction *transaction, const std::string &std) override;
|
||||
|
@@ -34,7 +34,7 @@ std::string Rbl::mapIpToAddress(std::string ipStr, Transaction *trans) {
|
||||
std::string addr;
|
||||
int h0, h1, h2, h3;
|
||||
std::string key;
|
||||
if (trans->m_rules->m_httpblKey.m_set == true) {
|
||||
if (trans && trans->m_rules->m_httpblKey.m_set == true) {
|
||||
key = trans->m_rules->m_httpblKey.m_value;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user