cppcheck: make static analysis more pedantic

This commit is contained in:
Felipe Zimmerle
2020-01-17 11:41:05 -03:00
parent cd9b8aa93b
commit 4f13fecbaf
23 changed files with 58 additions and 42 deletions

View File

@@ -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;

View File

@@ -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());
}
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -51,7 +51,7 @@ using variables::Variable;
using actions::transformations::None;
Rule::Rule(std::string marker)
Rule::Rule(const std::string &marker)
: m_accuracy(0),
m_actionsRuntimePos(),
m_actionsRuntimePre(),
@@ -303,7 +303,7 @@ void Rule::executeActionsIndependentOfChainedRuleResult(Transaction *trans,
}
bool Rule::executeOperatorAt(Transaction *trans, std::string key,
bool Rule::executeOperatorAt(Transaction *trans, const std::string &key,
std::string value, std::shared_ptr<RuleMessage> ruleMessage) {
#if MSC_EXEC_CLOCK_ENABLED
clock_t begin = clock();

View File

@@ -32,9 +32,10 @@ class Base64 {
static std::string decode(const std::string& data);
static std::string decode_forgiven(const std::string& data);
static void decode_forgiven_engine(unsigned char *output,
size_t output_size, size_t *aiming_size, const unsigned char *input,
size_t input_size);
static void decode_forgiven_engine(unsigned char *plain_text,
size_t plain_text_size, size_t *aiming_size,
const unsigned char *encoded,
size_t input_len);
};

View File

@@ -106,7 +106,7 @@ bool GeoLookup::setDataBase(const std::string& filePath,
bool GeoLookup::lookup(const std::string& target, Transaction *trans,
std::function<bool(int, std::string)> debug) {
std::function<bool(int, std::string)> debug) const {
if (m_version == NOT_LOADED) {
if (debug) {

View File

@@ -49,8 +49,8 @@ class GeoLookup {
bool setDataBase(const std::string& filePath, std::string *err);
void cleanUp();
bool lookup(const std::string& target, Transaction *t,
std::function<bool(int, std::string)> callback);
bool lookup(const std::string& target, Transaction *transaction,
std::function<bool(int, std::string)> debug) const;
private:
GeoLookup() :

View File

@@ -50,8 +50,8 @@ void HttpsClient::setKey(const std::string& key) {
m_key = "ModSec-key: " + key;
}
void HttpsClient::setRequestBody(const std::string& requestBody) {
m_requestBody = requestBody;
void HttpsClient::setRequestBody(const std::string& requestType) {
m_requestBody = requestType;
}
void HttpsClient::setRequestType(const std::string& requestType) {

View File

@@ -58,7 +58,7 @@ class Regex {
Regex& operator=(const Regex&) = delete;
std::list<SMatch> searchAll(const std::string& s) const;
int search(const std::string &s, SMatch *m) const;
int search(const std::string &s, SMatch *match) const;
int search(const std::string &s) const;
const std::string pattern;

View File

@@ -29,7 +29,7 @@ namespace utils {
double cpu_seconds(void);
std::string find_resource(const std::string& file, const std::string& param,
std::string find_resource(const std::string& file, const std::string& config,
std::string *err);
std::string get_path(const std::string& file);
std::list<std::string> expandEnv(const std::string& var, int flags);

View File

@@ -28,7 +28,7 @@ namespace modsecurity {
namespace variables {
Variable::Variable(std::string name)
Variable::Variable(const std::string &name)
: m_name(name),
m_collectionName("") {
size_t a = m_name.find(":");

View File

@@ -539,7 +539,7 @@ class VariableMonkeyResolution {
class Variable : public VariableMonkeyResolution {
public:
explicit Variable(std::string _name);
explicit Variable(const std::string &name);
explicit Variable(Variable *_name);
virtual ~Variable() { }

View File

@@ -42,7 +42,7 @@ class XML_NoDictElement : public Variable {
m_var(&m_name, &m_plain) {
}
void evaluate(Transaction *transaction,
void evaluate(Transaction *t,
Rule *rule,
std::vector<const VariableValue *> *l) override {
l->push_back(new VariableValue(&m_var));