Skip to content

Commit fbe0d1a

Browse files
committed
Added const reported by cppcheck 2.14
1 parent 1ec4c20 commit fbe0d1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+96
-95
lines changed

headers/modsecurity/anchored_set_variable_translation_proxy.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class AnchoredSetVariableTranslationProxy {
4242
: m_name(name),
4343
m_fount(fount)
4444
{
45-
m_translate = [](std::string *name, std::vector<const VariableValue *> *l) {
45+
m_translate = [](const std::string *name, std::vector<const VariableValue *> *l) {
4646
for (int i = 0; i < l->size(); ++i) {
4747
VariableValue *newVariableValue = new VariableValue(name, &l->at(i)->getKey(), &l->at(i)->getKey());
4848
const VariableValue *oldVariableValue = l->at(i);

headers/modsecurity/rule_message.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class RuleMessage {
4848
* unnecessary data duplication. Needs to be shrink down.
4949
*
5050
*/
51-
RuleMessage(RuleWithActions *rule, Transaction *trans) :
51+
RuleMessage(RuleWithActions *rule, const Transaction *trans) :
5252
m_accuracy(rule->m_accuracy),
5353
m_clientIpAddress(trans->m_clientIpAddress),
5454
m_data(""),
@@ -73,7 +73,7 @@ class RuleMessage {
7373
m_tags()
7474
{ }
7575

76-
explicit RuleMessage(RuleMessage *rule) :
76+
explicit RuleMessage(const RuleMessage *rule) :
7777
m_accuracy(rule->m_accuracy),
7878
m_clientIpAddress(rule->m_clientIpAddress),
7979
m_data(rule->m_data),
@@ -158,16 +158,16 @@ class RuleMessage {
158158
m_ver = "";
159159
}
160160

161-
std::string log() {
161+
std::string log() const {
162162
return log(this, 0);
163163
}
164-
std::string log(int props) {
164+
std::string log(int props) const {
165165
return log(this, props);
166166
}
167-
std::string log(int props, int responseCode) {
167+
std::string log(int props, int responseCode) const {
168168
return log(this, props, responseCode);
169169
}
170-
std::string errorLog() {
170+
std::string errorLog() const {
171171
return log(this,
172172
ClientLogMessageInfo | ErrorLogTailLogMessageInfo);
173173
}

headers/modsecurity/rule_with_actions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class RuleWithActions : public Rule {
136136
bool chainedParentNull = false);
137137

138138
std::vector<actions::Action *> getActionsByName(const std::string& name,
139-
Transaction *t);
139+
const Transaction *t);
140140
bool containsTag(const std::string& name, Transaction *t);
141141
bool containsMsg(const std::string& name, Transaction *t);
142142

headers/modsecurity/rules.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Rules {
5050
int append(Rules *from, const std::vector<int64_t> &ids, std::ostringstream *err) {
5151
size_t j = 0;
5252
for (; j < from->size(); j++) {
53-
RuleWithOperator *rule = dynamic_cast<RuleWithOperator *>(from->at(j).get());
53+
const RuleWithOperator *rule = dynamic_cast<RuleWithOperator *>(from->at(j).get());
5454
if (rule && std::binary_search(ids.begin(), ids.end(), rule->m_ruleId)) {
5555
if (err != NULL) {
5656
*err << "Rule id: " << std::to_string(rule->m_ruleId) \
@@ -68,7 +68,7 @@ class Rules {
6868
}
6969

7070
bool insert(std::shared_ptr<Rule> rule, const std::vector<int64_t> *ids, std::ostringstream *err) {
71-
RuleWithOperator *r = dynamic_cast<RuleWithOperator *>(rule.get());
71+
const RuleWithOperator *r = dynamic_cast<RuleWithOperator *>(rule.get());
7272
if (r && ids != nullptr && std::binary_search(ids->begin(), ids->end(), r->m_ruleId)) {
7373
if (err != nullptr) {
7474
*err << "Rule id: " << std::to_string(r->m_ruleId) \

headers/modsecurity/rules_set.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ extern "C" {
9393
#endif
9494

9595
RulesSet *msc_create_rules_set(void);
96-
void msc_rules_dump(RulesSet *rules);
96+
void msc_rules_dump(const RulesSet *rules);
9797
int msc_rules_merge(RulesSet *rules_dst, RulesSet *rules_from, const char **error);
9898
int msc_rules_add_remote(RulesSet *rules, const char *key, const char *uri,
9999
const char **error);

headers/modsecurity/rules_set_properties.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ConfigInt {
7070
bool m_set;
7171
int m_value;
7272

73-
void merge(ConfigInt *from) {
73+
void merge(const ConfigInt *from) {
7474
if (m_set == true || from->m_set == false) {
7575
return;
7676
}
@@ -87,7 +87,7 @@ class ConfigDouble {
8787
bool m_set;
8888
double m_value;
8989

90-
void merge(ConfigDouble *from) {
90+
void merge(const ConfigDouble *from) {
9191
if (m_set == true || from->m_set == false) {
9292
return;
9393
}
@@ -104,7 +104,7 @@ class ConfigString {
104104
bool m_set;
105105
std::string m_value;
106106

107-
void merge(ConfigString *from) {
107+
void merge(const ConfigString *from) {
108108
if (m_set == true || from->m_set == false) {
109109
return;
110110
}
@@ -150,7 +150,7 @@ class ConfigUnicodeMap {
150150
static void loadConfig(std::string f, double codePage,
151151
RulesSetProperties *driver, std::string *errg);
152152

153-
void merge(ConfigUnicodeMap *from) {
153+
void merge(const ConfigUnicodeMap *from) {
154154
if (from->m_set == false) {
155155
return;
156156
}

headers/modsecurity/transaction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ int msc_process_uri(Transaction *transaction, const char *uri,
704704
const char *protocol, const char *http_version);
705705

706706
/** @ingroup ModSecurity_C_API */
707-
const char *msc_get_response_body(Transaction *transaction);
707+
const char *msc_get_response_body(const Transaction *transaction);
708708

709709
/** @ingroup ModSecurity_C_API */
710710
size_t msc_get_response_body_length(Transaction *transaction);

src/actions/transformations/normalise_path.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int NormalisePath::normalize_path_inplace(unsigned char *input, int input_len,
6565
int win, int *changed) {
6666
unsigned char *src;
6767
unsigned char *dst;
68-
unsigned char *end;
68+
const unsigned char *end;
6969
int ldst = 0;
7070
int hitroot = 0;
7171
int done = 0;
@@ -185,7 +185,7 @@ int NormalisePath::normalize_path_inplace(unsigned char *input, int input_len,
185185

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

190190
while ((src < end)
191191
&& ((*(src + 1) == '/') || (win && (*(src + 1) == '\\'))) ) {

src/actions/transformations/sql_hex_decode.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ std::string SqlHexDecode::evaluate(const std::string &value,
6666

6767

6868
int SqlHexDecode::inplace(unsigned char *data, int len) {
69-
unsigned char *d, *begin = data;
69+
unsigned char *d;
70+
const unsigned char *begin = data;
7071
int count = 0;
7172

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

105106
*d = '\0';
106-
return strlen(reinterpret_cast<char *>(begin));
107+
return strlen(reinterpret_cast<const char *>(begin));
107108
}
108109

109110

src/collection/backend/lmdb.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ void LMDB::resolveMultiMatches(const std::string& var,
557557
continue;
558558
}
559559

560-
char *a = reinterpret_cast<char *>(key.mv_data);
560+
const char *a = reinterpret_cast<char *>(key.mv_data);
561561
if (strncmp(var.c_str(), a, keySize) == 0) {
562562
std::string key_to_insert(reinterpret_cast<char *>(key.mv_data), key.mv_size);
563563
l->insert(l->begin(), new VariableValue(&m_name, &key_to_insert, &collectionData.getValue()));

src/engine/lua.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ int Lua::blob_keeper(lua_State *L, const void *p, size_t sz, void *ud) {
114114

115115

116116
const char *Lua::blob_reader(lua_State *L, void *ud, size_t *size) {
117-
LuaScriptBlob *lsb = static_cast<LuaScriptBlob *>(ud);
117+
const LuaScriptBlob *lsb = static_cast<LuaScriptBlob *>(ud);
118118
const char *data = lsb->read(size);
119119
return data;
120120
}
121121
#endif
122122

123123

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

409409

410410
std::string Lua::applyTransformations(lua_State *L, Transaction *t,
411-
int idx, std::string var) {
411+
int idx, const std::string &var) {
412412
std::string newVar = var;
413413

414414
if (lua_isuserdata(L, idx) || lua_isnoneornil(L, idx)) {

src/engine/lua.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Lua {
8080
static int getvars(lua_State *L);
8181
static int setvar(lua_State *L);
8282
static std::string applyTransformations(lua_State *L, Transaction *t,
83-
int idx, std::string var);
83+
int idx, const std::string &var);
8484

8585
LuaScriptBlob m_blob;
8686
#endif

src/operators/geo_lookup.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class GeoLookup : public Operator {
3333

3434
protected:
3535
// cppcheck-suppress functionStatic
36-
bool debug(Transaction *transaction, int x, const std::string &a) {
36+
bool debug(const Transaction *transaction, int x, const std::string &a) {
3737
ms_dbg_a(transaction, x, a);
3838
return true;
3939
}

src/operators/pm.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ bool Pm::init(const std::string &file, std::string *error) {
132132
std::istream_iterator<std::string>(),
133133
back_inserter(vec));
134134

135-
for (auto &a : vec) {
135+
for (const auto &a : vec) {
136136
acmp_add_pattern(m_p, a.c_str(), NULL, NULL, a.length());
137137
}
138138

src/operators/rbl.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ std::string Rbl::mapIpToAddress(const std::string &ipStr, Transaction *trans) co
6868

6969

7070
void Rbl::futherInfo_httpbl(struct sockaddr_in *sin, const std::string &ipStr,
71-
Transaction *trans) {
72-
char *respBl;
71+
const Transaction *trans) {
72+
const char *respBl;
7373
int first, days, score, type;
7474
#ifndef NO_LOGS
7575
std::string ptype;
@@ -126,7 +126,7 @@ void Rbl::futherInfo_httpbl(struct sockaddr_in *sin, const std::string &ipStr,
126126

127127

128128
void Rbl::futherInfo_spamhaus(unsigned int high8bits, const std::string &ipStr,
129-
Transaction *trans) {
129+
const Transaction *trans) {
130130
switch (high8bits) {
131131
case 2:
132132
case 3:
@@ -153,7 +153,7 @@ void Rbl::futherInfo_spamhaus(unsigned int high8bits, const std::string &ipStr,
153153

154154

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

181181

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

186186
switch (provider) {

src/operators/rbl.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ class Rbl : public Operator {
8484
std::string mapIpToAddress(const std::string &ipStr, Transaction *trans) const;
8585

8686
static void futherInfo_httpbl(struct sockaddr_in *sin, const std::string &ipStr,
87-
Transaction *trans);
87+
const Transaction *trans);
8888
static void futherInfo_spamhaus(unsigned int high8bits, const std::string &ipStr,
89-
Transaction *trans);
89+
const Transaction *trans);
9090
static void futherInfo_uribl(unsigned int high8bits, const std::string &ipStr,
91-
Transaction *trans);
91+
const Transaction *trans);
9292
static void furtherInfo(struct sockaddr_in *sin, const std::string &ipStr,
93-
Transaction *trans, RblProvider provider);
93+
const Transaction *trans, RblProvider provider);
9494

9595
private:
9696
std::string m_service;

src/operators/validate_dtd.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ValidateDTD : public Operator {
6464

6565

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

8282

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

9999

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

103103
private:

src/operators/validate_schema.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ValidateSchema : public Operator {
7676

7777

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

9494

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

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

114114
private:

src/operators/verify_cpf.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int VerifyCPF::convert_to_int(const char c) {
3838
}
3939

4040

41-
bool VerifyCPF::verify(const char *cpfnumber, int len) {
41+
bool VerifyCPF::verify(const char *cpfnumber, int len) const {
4242
int factor, part_1, part_2, var_len = len;
4343
unsigned int sum = 0, i = 0, cpf_len = 11, c;
4444
int cpf[11];

src/operators/verify_cpf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class VerifyCPF : public Operator {
5050
const std::string& input,
5151
std::shared_ptr<RuleMessage> ruleMessage) override;
5252

53-
bool verify(const char *ssnumber, int len);
53+
bool verify(const char *ssnumber, int len) const;
5454

5555
private:
5656
static int convert_to_int(const char c);

src/operators/verify_svnr.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int VerifySVNR::convert_to_int(const char c) {
2424
}
2525

2626

27-
bool VerifySVNR::verify(const char *svnrnumber, int len) {
27+
bool VerifySVNR::verify(const char *svnrnumber, int len) const {
2828
int var_len = len;
2929
int sum = 0;
3030
unsigned int i = 0, svnr_len = 10;

src/operators/verify_svnr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class VerifySVNR : public Operator {
3636
const std::string& input,
3737
std::shared_ptr<RuleMessage> ruleMessage) override;
3838

39-
bool verify(const char *ssnumber, int len);
39+
bool verify(const char *ssnumber, int len) const;
4040

4141
private:
4242
Regex *m_re;

src/parser/driver.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ int Driver::addSecRule(std::unique_ptr<RuleWithActions> r) {
108108
}
109109

110110
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
111-
Rules *rules = m_rulesSetPhases[i];
111+
const Rules *rules = m_rulesSetPhases[i];
112112
for (int j = 0; j < rules->size(); j++) {
113-
RuleWithOperator *lr = dynamic_cast<RuleWithOperator *>(rules->at(j).get());
113+
const RuleWithOperator *lr = dynamic_cast<RuleWithOperator *>(rules->at(j).get());
114114
if (lr && lr->m_ruleId == rule->m_ruleId) {
115115
m_parserError << "Rule id: " << std::to_string(rule->m_ruleId) \
116116
<< " is duplicated" << std::endl;

src/request_body_processor/json.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ int JSON::addArgument(const std::string& value) {
131131
std::string path;
132132

133133
for (size_t i = 0; i < m_containers.size(); i++) {
134-
JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
134+
const JSONContainerArray *a = dynamic_cast<JSONContainerArray *>(
135135
m_containers[i]);
136136
path = path + m_containers[i]->m_name;
137137
if (a != NULL) {

0 commit comments

Comments
 (0)