Skip to content

Commit

Permalink
Added const reported by cppcheck 2.11 & 2.14
Browse files Browse the repository at this point in the history
  • Loading branch information
eduar-hte committed Apr 29, 2024
1 parent be7f6d4 commit 0708b26
Show file tree
Hide file tree
Showing 44 changed files with 96 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AnchoredSetVariableTranslationProxy {
: m_name(name),
m_fount(fount)
{
m_translate = [](std::string *name, std::vector<const VariableValue *> *l) {
m_translate = [](const std::string *name, std::vector<const VariableValue *> *l) {
for (int i = 0; i < l->size(); ++i) {
VariableValue *newVariableValue = new VariableValue(name, &l->at(i)->getKey(), &l->at(i)->getKey());
const VariableValue *oldVariableValue = l->at(i);
Expand Down
12 changes: 6 additions & 6 deletions headers/modsecurity/rule_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RuleMessage {
* unnecessary data duplication. Needs to be shrink down.
*
*/
RuleMessage(RuleWithActions *rule, Transaction *trans) :
RuleMessage(RuleWithActions *rule, const Transaction *trans) :
m_accuracy(rule->m_accuracy),
m_clientIpAddress(trans->m_clientIpAddress),
m_data(""),
Expand All @@ -73,7 +73,7 @@ class RuleMessage {
m_tags()
{ }

explicit RuleMessage(RuleMessage *rule) :
explicit RuleMessage(const RuleMessage *rule) :
m_accuracy(rule->m_accuracy),
m_clientIpAddress(rule->m_clientIpAddress),
m_data(rule->m_data),
Expand Down Expand Up @@ -158,16 +158,16 @@ class RuleMessage {
m_ver = "";
}

std::string log() {
std::string log() const {
return log(this, 0);
}
std::string log(int props) {
std::string log(int props) const {
return log(this, props);
}
std::string log(int props, int responseCode) {
std::string log(int props, int responseCode) const {
return log(this, props, responseCode);
}
std::string errorLog() {
std::string errorLog() const {
return log(this,
ClientLogMessageInfo | ErrorLogTailLogMessageInfo);
}
Expand Down
2 changes: 1 addition & 1 deletion headers/modsecurity/rule_with_actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class RuleWithActions : public Rule {
bool chainedParentNull = false);

std::vector<actions::Action *> getActionsByName(const std::string& name,
Transaction *t);
const Transaction *t);
bool containsTag(const std::string& name, Transaction *t);
bool containsMsg(const std::string& name, Transaction *t);

Expand Down
4 changes: 2 additions & 2 deletions headers/modsecurity/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Rules {
int append(Rules *from, const std::vector<int64_t> &ids, std::ostringstream *err) {
size_t j = 0;
for (; j < from->size(); j++) {
RuleWithOperator *rule = dynamic_cast<RuleWithOperator *>(from->at(j).get());
const RuleWithOperator *rule = dynamic_cast<RuleWithOperator *>(from->at(j).get());
if (rule && std::binary_search(ids.begin(), ids.end(), rule->m_ruleId)) {
if (err != NULL) {
*err << "Rule id: " << std::to_string(rule->m_ruleId) \
Expand All @@ -68,7 +68,7 @@ class Rules {
}

bool insert(std::shared_ptr<Rule> rule, const std::vector<int64_t> *ids, std::ostringstream *err) {
RuleWithOperator *r = dynamic_cast<RuleWithOperator *>(rule.get());
const RuleWithOperator *r = dynamic_cast<RuleWithOperator *>(rule.get());
if (r && ids != nullptr && std::binary_search(ids->begin(), ids->end(), r->m_ruleId)) {
if (err != nullptr) {
*err << "Rule id: " << std::to_string(r->m_ruleId) \
Expand Down
2 changes: 1 addition & 1 deletion headers/modsecurity/rules_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extern "C" {
#endif

RulesSet *msc_create_rules_set(void);
void msc_rules_dump(RulesSet *rules);
void msc_rules_dump(const RulesSet *rules);
int msc_rules_merge(RulesSet *rules_dst, RulesSet *rules_from, const char **error);
int msc_rules_add_remote(RulesSet *rules, const char *key, const char *uri,
const char **error);
Expand Down
8 changes: 4 additions & 4 deletions headers/modsecurity/rules_set_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ConfigInt {
bool m_set;
int m_value;

void merge(ConfigInt *from) {
void merge(const ConfigInt *from) {
if (m_set == true || from->m_set == false) {
return;
}
Expand All @@ -87,7 +87,7 @@ class ConfigDouble {
bool m_set;
double m_value;

void merge(ConfigDouble *from) {
void merge(const ConfigDouble *from) {
if (m_set == true || from->m_set == false) {
return;
}
Expand All @@ -104,7 +104,7 @@ class ConfigString {
bool m_set;
std::string m_value;

void merge(ConfigString *from) {
void merge(const ConfigString *from) {
if (m_set == true || from->m_set == false) {
return;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ class ConfigUnicodeMap {
static void loadConfig(std::string f, double codePage,
RulesSetProperties *driver, std::string *errg);

void merge(ConfigUnicodeMap *from) {
void merge(const ConfigUnicodeMap *from) {
if (from->m_set == false) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion headers/modsecurity/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ int msc_process_uri(Transaction *transaction, const char *uri,
const char *protocol, const char *http_version);

/** @ingroup ModSecurity_C_API */
const char *msc_get_response_body(Transaction *transaction);
const char *msc_get_response_body(const Transaction *transaction);

/** @ingroup ModSecurity_C_API */
size_t msc_get_response_body_length(Transaction *transaction);
Expand Down
4 changes: 2 additions & 2 deletions src/actions/transformations/normalise_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int NormalisePath::normalize_path_inplace(unsigned char *input, int input_len,
int win, int *changed) {
unsigned char *src;
unsigned char *dst;
unsigned char *end;
const unsigned char *end;
int ldst = 0;
int hitroot = 0;
int done = 0;
Expand Down Expand Up @@ -185,7 +185,7 @@ int NormalisePath::normalize_path_inplace(unsigned char *input, int input_len,

/* Skip to the last forward slash when multiple are used. */
if (*src == '/') {
unsigned char *oldsrc = src;
const unsigned char *oldsrc = src;

while ((src < end)
&& ((*(src + 1) == '/') || (win && (*(src + 1) == '\\'))) ) {
Expand Down
5 changes: 3 additions & 2 deletions src/actions/transformations/sql_hex_decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ std::string SqlHexDecode::evaluate(const std::string &value,


int SqlHexDecode::inplace(unsigned char *data, int len) {
unsigned char *d, *begin = data;
unsigned char *d;
const unsigned char *begin = data;
int count = 0;

if ((data == NULL) || (len == 0)) {
Expand Down Expand Up @@ -103,7 +104,7 @@ int SqlHexDecode::inplace(unsigned char *data, int len) {
}

*d = '\0';
return strlen(reinterpret_cast<char *>(begin));
return strlen(reinterpret_cast<const char *>(begin));
}


Expand Down
2 changes: 1 addition & 1 deletion src/collection/backend/lmdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void LMDB::resolveMultiMatches(const std::string& var,
continue;
}

char *a = reinterpret_cast<char *>(key.mv_data);
const char *a = reinterpret_cast<char *>(key.mv_data);
if (strncmp(var.c_str(), a, keySize) == 0) {
std::string key_to_insert(reinterpret_cast<char *>(key.mv_data), key.mv_size);
l->insert(l->begin(), new VariableValue(&m_name, &key_to_insert, &collectionData.getValue()));
Expand Down
6 changes: 3 additions & 3 deletions src/engine/lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ int Lua::blob_keeper(lua_State *L, const void *p, size_t sz, void *ud) {


const char *Lua::blob_reader(lua_State *L, void *ud, size_t *size) {
LuaScriptBlob *lsb = static_cast<LuaScriptBlob *>(ud);
const LuaScriptBlob *lsb = static_cast<LuaScriptBlob *>(ud);
const char *data = lsb->read(size);
return data;
}
#endif


int Lua::run(Transaction *t, const std::string &str) {
int Lua::run(Transaction *t, const std::string &str) { // cppcheck-suppress constParameterPointer
#ifdef WITH_LUA
std::string luaRet;
const char *a = NULL;
Expand Down Expand Up @@ -408,7 +408,7 @@ int Lua::setvar(lua_State *L) {


std::string Lua::applyTransformations(lua_State *L, Transaction *t,
int idx, std::string var) {
int idx, const std::string &var) {
std::string newVar = var;

if (lua_isuserdata(L, idx) || lua_isnoneornil(L, idx)) {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Lua {
static int getvars(lua_State *L);
static int setvar(lua_State *L);
static std::string applyTransformations(lua_State *L, Transaction *t,
int idx, std::string var);
int idx, const std::string &var);

LuaScriptBlob m_blob;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/operators/geo_lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class GeoLookup : public Operator {

protected:
// cppcheck-suppress functionStatic
bool debug(Transaction *transaction, int x, const std::string &a) {
bool debug(const Transaction *transaction, int x, const std::string &a) {
ms_dbg_a(transaction, x, a);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/operators/pm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ bool Pm::init(const std::string &file, std::string *error) {
std::istream_iterator<std::string>(),
back_inserter(vec));

for (auto &a : vec) {
for (const auto &a : vec) {
acmp_add_pattern(m_p, a.c_str(), NULL, NULL, a.length());
}

Expand Down
10 changes: 5 additions & 5 deletions src/operators/rbl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ std::string Rbl::mapIpToAddress(const std::string &ipStr, Transaction *trans) co


void Rbl::futherInfo_httpbl(struct sockaddr_in *sin, const std::string &ipStr,
Transaction *trans) {
char *respBl;
const Transaction *trans) {
const char *respBl;
int first, days, score, type;
#ifndef NO_LOGS
std::string ptype;
Expand Down Expand Up @@ -126,7 +126,7 @@ void Rbl::futherInfo_httpbl(struct sockaddr_in *sin, const std::string &ipStr,


void Rbl::futherInfo_spamhaus(unsigned int high8bits, const std::string &ipStr,
Transaction *trans) {
const Transaction *trans) {
switch (high8bits) {
case 2:
case 3:
Expand All @@ -153,7 +153,7 @@ void Rbl::futherInfo_spamhaus(unsigned int high8bits, const std::string &ipStr,


void Rbl::futherInfo_uribl(unsigned int high8bits, const std::string &ipStr,
Transaction *trans) {
const Transaction *trans) {
switch (high8bits) {
case 2:
ms_dbg_a(trans, 4, "RBL lookup of " + ipStr + " succeeded (BLACK).");
Expand All @@ -180,7 +180,7 @@ void Rbl::futherInfo_uribl(unsigned int high8bits, const std::string &ipStr,


void Rbl::furtherInfo(struct sockaddr_in *sin, const std::string &ipStr,
Transaction *trans, RblProvider provider) {
const Transaction *trans, RblProvider provider) {
unsigned int high8bits = sin->sin_addr.s_addr >> 24;

switch (provider) {
Expand Down
8 changes: 4 additions & 4 deletions src/operators/rbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ class Rbl : public Operator {
std::string mapIpToAddress(const std::string &ipStr, Transaction *trans) const;

static void futherInfo_httpbl(struct sockaddr_in *sin, const std::string &ipStr,
Transaction *trans);
const Transaction *trans);
static void futherInfo_spamhaus(unsigned int high8bits, const std::string &ipStr,
Transaction *trans);
const Transaction *trans);
static void futherInfo_uribl(unsigned int high8bits, const std::string &ipStr,
Transaction *trans);
const Transaction *trans);
static void furtherInfo(struct sockaddr_in *sin, const std::string &ipStr,
Transaction *trans, RblProvider provider);
const Transaction *trans, RblProvider provider);

private:
std::string m_service;
Expand Down
6 changes: 3 additions & 3 deletions src/operators/validate_dtd.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ValidateDTD : public Operator {


static void error_runtime(void *ctx, const char *msg, ...) {
Transaction *t = reinterpret_cast<Transaction *>(ctx);
const Transaction *t = reinterpret_cast<Transaction *>(ctx);
char buf[1024];
std::string s;
va_list args;
Expand All @@ -81,7 +81,7 @@ class ValidateDTD : public Operator {


static void warn_runtime(void *ctx, const char *msg, ...) {
Transaction *t = reinterpret_cast<Transaction *>(ctx);
const Transaction *t = reinterpret_cast<Transaction *>(ctx);
char buf[1024];
std::string s;
va_list args;
Expand All @@ -97,7 +97,7 @@ class ValidateDTD : public Operator {
}


static void null_error(void *ctx, const char *msg, ...) {
static void null_error(void *ctx, const char *msg, ...) { // cppcheck-suppress[constParameterPointer,constParameterCallback]
}

private:
Expand Down
6 changes: 3 additions & 3 deletions src/operators/validate_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ValidateSchema : public Operator {


static void error_runtime(void *ctx, const char *msg, ...) {
Transaction *t = reinterpret_cast<Transaction *>(ctx);
const Transaction *t = reinterpret_cast<Transaction *>(ctx);
char buf[1024];
std::string s;
va_list args;
Expand All @@ -93,7 +93,7 @@ class ValidateSchema : public Operator {


static void warn_runtime(void *ctx, const char *msg, ...) {
Transaction *t = reinterpret_cast<Transaction *>(ctx);
const Transaction *t = reinterpret_cast<Transaction *>(ctx);
char buf[1024];
std::string s;
va_list args;
Expand All @@ -108,7 +108,7 @@ class ValidateSchema : public Operator {
ms_dbg_a(t, 4, s);
}

static void null_error(void *ctx, const char *msg, ...) {
static void null_error(void *ctx, const char *msg, ...) { // cppcheck-suppress[constParameterPointer,constParameterCallback]
}

private:
Expand Down
2 changes: 1 addition & 1 deletion src/operators/verify_cpf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int VerifyCPF::convert_to_int(const char c) {
}


bool VerifyCPF::verify(const char *cpfnumber, int len) {
bool VerifyCPF::verify(const char *cpfnumber, int len) const {
int factor, part_1, part_2, var_len = len;
unsigned int sum = 0, i = 0, cpf_len = 11, c;
int cpf[11];
Expand Down
2 changes: 1 addition & 1 deletion src/operators/verify_cpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class VerifyCPF : public Operator {
const std::string& input,
std::shared_ptr<RuleMessage> ruleMessage) override;

bool verify(const char *ssnumber, int len);
bool verify(const char *ssnumber, int len) const;

private:
static int convert_to_int(const char c);
Expand Down
2 changes: 1 addition & 1 deletion src/operators/verify_svnr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int VerifySVNR::convert_to_int(const char c) {
}


bool VerifySVNR::verify(const char *svnrnumber, int len) {
bool VerifySVNR::verify(const char *svnrnumber, int len) const {
int var_len = len;
int sum = 0;
unsigned int i = 0, svnr_len = 10;
Expand Down
2 changes: 1 addition & 1 deletion src/operators/verify_svnr.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class VerifySVNR : public Operator {
const std::string& input,
std::shared_ptr<RuleMessage> ruleMessage) override;

bool verify(const char *ssnumber, int len);
bool verify(const char *ssnumber, int len) const;

private:
Regex *m_re;
Expand Down
4 changes: 2 additions & 2 deletions src/parser/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ int Driver::addSecRule(std::unique_ptr<RuleWithActions> r) {
}

for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
Rules *rules = m_rulesSetPhases[i];
const Rules *rules = m_rulesSetPhases[i];
for (int j = 0; j < rules->size(); j++) {
RuleWithOperator *lr = dynamic_cast<RuleWithOperator *>(rules->at(j).get());
const RuleWithOperator *lr = dynamic_cast<RuleWithOperator *>(rules->at(j).get());
if (lr && lr->m_ruleId == rule->m_ruleId) {
m_parserError << "Rule id: " << std::to_string(rule->m_ruleId) \
<< " is duplicated" << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/request_body_processor/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int JSON::addArgument(const std::string& value) {
std::string path;

for (size_t i = 0; i < m_containers.size(); i++) {
JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
const JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
m_containers[i]);
path = path + m_containers[i]->m_name;
if (a != NULL) {
Expand Down
Loading

0 comments on commit 0708b26

Please sign in to comment.