Skip to content

Commit

Permalink
Added const reported by cppcheck 2.14
Browse files Browse the repository at this point in the history
  • Loading branch information
eduar-hte committed Aug 21, 2024
1 parent 7edd368 commit 00b9081
Show file tree
Hide file tree
Showing 43 changed files with 98 additions and 100 deletions.
2 changes: 1 addition & 1 deletion examples/multithread/multithread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main (int argc, char *argv[]) {
modsec->setConnectorInformation("ModSecurity-test v0.0.1-alpha (Simple " \
"example on how to use ModSecurity API");

char main_rule_uri[] = "basic_rules.conf";
const char main_rule_uri[] = "basic_rules.conf";
auto rules = std::make_unique<modsecurity::RulesSet>();
if (rules->loadFromUri(main_rule_uri) < 0) {
std::cerr << "Problems loading the rules..." << std::endl;
Expand Down
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
2 changes: 1 addition & 1 deletion headers/modsecurity/rule_with_actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class RuleWithActions : public Rule {
bool chainedParentNull = false) const;

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
2 changes: 1 addition & 1 deletion headers/modsecurity/rule_with_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class RuleWithOperator : public RuleWithActions {
static void cleanMatchedVars(Transaction *trasn);


std::string getOperatorName() const;
const std::string& getOperatorName() const;

virtual std::string getReference() override {
return std::to_string(m_ruleId);
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 @@ -709,7 +709,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
11 changes: 4 additions & 7 deletions src/actions/transformations/normalise_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ bool NormalisePath::transform(std::string &value, const Transaction *trans) cons
* IMP1 Assumes NUL-terminated
*/
bool NormalisePath::normalize_path_inplace(std::string &val, const bool win) {
unsigned char *src;
unsigned char *dst;
unsigned char *end;
int hitroot = 0;
int done = 0;
int relative;
Expand All @@ -49,13 +46,13 @@ bool NormalisePath::normalize_path_inplace(std::string &val, const bool win) {
* ENH: Deal with UNC and drive letters?
*/

src = dst = input;
end = input + (input_len - 1);
auto src = input;
auto dst = input;
const unsigned char *end = input + (input_len - 1);

relative = ((*input == '/') || (win && (*input == '\\'))) ? 0 : 1;
trailing = ((*end == '/') || (win && (*end == '\\'))) ? 1 : 0;


while (!done && (src <= end) && (dst <= end)) {
/* Convert backslash to forward slash on Windows only. */
if (win) {
Expand Down Expand Up @@ -152,7 +149,7 @@ bool NormalisePath::normalize_path_inplace(std::string &val, const bool win) {

/* 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
2 changes: 1 addition & 1 deletion src/audit_log/writer/parallel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Parallel::~Parallel() {
}


inline std::string Parallel::logFilePath(time_t *t,
inline std::string Parallel::logFilePath(const time_t *t,
int part) {
std::string name;

Expand Down
2 changes: 1 addition & 1 deletion src/audit_log/writer/parallel.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Parallel : public Writer {
YearMonthDayAndTimeFileName = 8,
};

static inline std::string logFilePath(time_t *t, int part);
static inline std::string logFilePath(const time_t *t, int part);
};

} // namespace writer
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 @@ -559,7 +559,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
4 changes: 2 additions & 2 deletions src/engine/lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,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
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/operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Operator {

std::string m_match_message;
bool m_negation;
std::string m_op;
const std::string m_op;
std::string m_param;
std::unique_ptr<RunTimeString> m_string;
bool m_couldContainsMacro;
Expand Down
10 changes: 5 additions & 5 deletions src/operators/rbl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,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 @@ -127,7 +127,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 Down Expand Up @@ -155,7 +155,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, fmt::format("RBL lookup of {} succeeded (BLACK).",
Expand Down Expand Up @@ -186,7 +186,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 @@ -88,13 +88,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 @@ -39,7 +39,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,
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 @@ -25,7 +25,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,
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 << fmt::format("Rule id: {} is duplicated",
rule->m_ruleId) << 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 @@ -132,7 +132,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.append(m_containers[i]->m_name);
if (a != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/request_body_processor/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class JSON {
static int yajl_end_array(void *ctx);

bool isPreviousArray() const {
JSONContainerArray *prev = NULL;
const JSONContainerArray *prev = NULL;
if (m_containers.size() < 1) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/request_body_processor/xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class XML {
static xmlParserInputBufferPtr unloadExternalEntity(const char *URI,
xmlCharEncoding enc);

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


Expand Down
Loading

0 comments on commit 00b9081

Please sign in to comment.