Skip to content

Commit 1c1ccf6

Browse files
authored
Merge pull request #3508 from airween/v3/cppcheckvariableh
fix: cppcheck warnings
2 parents c3e31de + 1e75649 commit 1c1ccf6

File tree

12 files changed

+70
-15
lines changed

12 files changed

+70
-15
lines changed

headers/modsecurity/anchored_set_variable.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,26 @@ class AnchoredSetVariable : public std::unordered_multimap<std::string,
8484

8585
void setCopy(std::string key, std::string value, size_t offset);
8686

87+
void resolve(std::vector<const VariableValue *> *l) const;
88+
void resolve(std::vector<const VariableValue *> *l,
89+
const variables::KeyExclusions &ke) const;
90+
91+
// keep the old signatures for ABI compatibility
8792
void resolve(std::vector<const VariableValue *> *l);
8893
void resolve(std::vector<const VariableValue *> *l,
8994
variables::KeyExclusions &ke);
9095

9196
void resolve(const std::string &key,
9297
std::vector<const VariableValue *> *l);
9398

99+
void resolveRegularExpression(Utils::Regex *r,
100+
std::vector<const VariableValue *> *l) const;
101+
102+
void resolveRegularExpression(Utils::Regex *r,
103+
std::vector<const VariableValue *> *l,
104+
const variables::KeyExclusions &ke) const;
105+
106+
// keep the old signatures for ABI compatibility
94107
void resolveRegularExpression(Utils::Regex *r,
95108
std::vector<const VariableValue *> *l);
96109

headers/modsecurity/audit_log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class AuditLog {
172172

173173
bool saveIfRelevant(Transaction *transaction);
174174
bool saveIfRelevant(Transaction *transaction, int parts);
175+
bool isRelevant(int status) const;
175176
bool isRelevant(int status);
176177

177178
static int addParts(int parts, std::string_view new_parts);

headers/modsecurity/rules_set.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class RulesSet : public RulesSetProperties {
7575
int merge(RulesSet *rules);
7676

7777
int evaluate(int phase, Transaction *transaction);
78+
std::string getParserError() const;
7879
std::string getParserError();
7980

8081
void debug(int level, const std::string &id, const std::string &uri,

src/actions/transformations/url_decode_uni.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static inline bool inplace(std::string &value,
3535
const auto input_len = value.length();
3636

3737
std::string::size_type i, count, fact, j, xv;
38-
int Code, hmap = -1;
38+
int hmap = -1;
3939

4040
i = count = 0;
4141
while (i < input_len) {
@@ -50,13 +50,16 @@ static inline bool inplace(std::string &value,
5050
(VALID_HEX(input[i + 3])) &&
5151
(VALID_HEX(input[i + 4])) &&
5252
(VALID_HEX(input[i + 5]))) {
53-
Code = 0;
53+
5454
fact = 1;
5555

5656
if (t
5757
&& t->m_rules->m_unicodeMapTable.m_set == true
5858
&& t->m_rules->m_unicodeMapTable.m_unicodeMapTable != NULL
5959
&& t->m_rules->m_unicodeMapTable.m_unicodeCodePage > 0) {
60+
61+
int Code = 0;
62+
6063
for (j = 5; j >= 2; j--) {
6164
if (isxdigit((input[i+j]))) {
6265
if (input[i+j] >= 97) {

src/anchored_set_variable.cc

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,22 @@ void AnchoredSetVariable::set(const std::string &key,
6767

6868

6969
void AnchoredSetVariable::resolve(
70-
std::vector<const VariableValue *> *l) {
70+
std::vector<const VariableValue *> *l) const {
7171
for (const auto& x : *this) {
7272
l->insert(l->begin(), new VariableValue(x.second));
7373
}
7474
}
7575

7676

77+
void AnchoredSetVariable::resolve(
78+
std::vector<const VariableValue *> *l) {
79+
static_cast<const AnchoredSetVariable&>(*this).resolve(l);
80+
}
81+
82+
7783
void AnchoredSetVariable::resolve(
7884
std::vector<const VariableValue *> *l,
79-
variables::KeyExclusions &ke) {
85+
const variables::KeyExclusions &ke) const {
8086
for (const auto& x : *this) {
8187
if (!ke.toOmit(x.first)) {
8288
l->insert(l->begin(), new VariableValue(x.second));
@@ -88,6 +94,13 @@ void AnchoredSetVariable::resolve(
8894
}
8995

9096

97+
void AnchoredSetVariable::resolve(
98+
std::vector<const VariableValue *> *l,
99+
variables::KeyExclusions &ke) { // cppcheck-suppress constParameterReference
100+
static_cast<const AnchoredSetVariable&>(*this).resolve(l, ke);
101+
}
102+
103+
91104
void AnchoredSetVariable::resolve(const std::string &key,
92105
std::vector<const VariableValue *> *l) {
93106
auto range = this->equal_range(key);
@@ -109,7 +122,7 @@ std::unique_ptr<std::string> AnchoredSetVariable::resolveFirst(
109122

110123

111124
void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
112-
std::vector<const VariableValue *> *l) {
125+
std::vector<const VariableValue *> *l) const {
113126
for (const auto& x : *this) {
114127
int ret = Utils::regex_search(x.first, *r);
115128
if (ret <= 0) {
@@ -120,9 +133,15 @@ void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
120133
}
121134

122135

136+
void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
137+
std::vector<const VariableValue *> *l) {
138+
static_cast<const AnchoredSetVariable&>(*this).resolveRegularExpression(r, l);
139+
}
140+
141+
123142
void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
124143
std::vector<const VariableValue *> *l,
125-
variables::KeyExclusions &ke) {
144+
const variables::KeyExclusions &ke) const {
126145
for (const auto& x : *this) {
127146
int ret = Utils::regex_search(x.first, *r);
128147
if (ret <= 0) {
@@ -138,4 +157,11 @@ void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
138157
}
139158

140159

160+
void AnchoredSetVariable::resolveRegularExpression(Utils::Regex *r,
161+
std::vector<const VariableValue *> *l,
162+
variables::KeyExclusions &ke) { // cppcheck-suppress constParameterReference
163+
static_cast<const AnchoredSetVariable&>(*this).resolveRegularExpression(r, l, ke);
164+
}
165+
166+
141167
} // namespace modsecurity

src/audit_log/audit_log.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ bool AuditLog::init(std::string *error) {
248248
}
249249

250250

251-
bool AuditLog::isRelevant(int status) {
251+
bool AuditLog::isRelevant(int status) const {
252252
std::string sstatus = std::to_string(status);
253253

254254
if (m_relevant.empty()) {
@@ -264,6 +264,10 @@ bool AuditLog::isRelevant(int status) {
264264
Utils::Regex(m_relevant)) != 0;
265265
}
266266

267+
bool AuditLog::isRelevant(int status) {
268+
return static_cast<const AuditLog&>(*this).isRelevant(status);
269+
}
270+
267271

268272
bool AuditLog::saveIfRelevant(Transaction *transaction) {
269273
return saveIfRelevant(transaction, -1);

src/rules_set.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ int RulesSet::load(const char *plainRules) {
101101
}
102102

103103

104-
std::string RulesSet::getParserError() {
104+
std::string RulesSet::getParserError() const {
105105
return this->m_parserError.str();
106106
}
107107

108+
std::string RulesSet::getParserError() {
109+
return static_cast<const RulesSet&>(*this).getParserError();
110+
}
111+
108112
void RulesSet::cleanMatchedVars(Transaction *trans) {
109113
ms_dbg_a(trans, 9, "Matched vars cleaned.");
110114
// cppcheck-suppress ctunullpointer
@@ -119,7 +123,7 @@ int RulesSet::evaluate(int phase, Transaction *t) {
119123
return 0;
120124
}
121125

122-
Rules *rules = m_rulesSetPhases[phase];
126+
const Rules *rules = m_rulesSetPhases[phase];
123127

124128
ms_dbg_a(t, 9, "This phase consists of " \
125129
+ std::to_string(rules->size()) + " rule(s).");

src/rules_set_properties.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ void ConfigUnicodeMap::loadConfig(std::string f, double configCodePage,
3232
char *hmap = NULL;
3333
const char *p = NULL;
3434
char *savedptr = NULL;
35-
const char *ucode = NULL;
3635
int found = 0;
3736
int length = 0;
3837
int processing = 0;
@@ -99,7 +98,7 @@ void ConfigUnicodeMap::loadConfig(std::string f, double configCodePage,
9998
processing = 1;
10099

101100
if (mapping != NULL) {
102-
ucode = strtok_r(mapping, ":", &hmap);
101+
const char *ucode = strtok_r(mapping, ":", &hmap);
103102
int code = strtol(ucode, nullptr, 16);
104103
int map = strtol(hmap, nullptr, 16);
105104
if (code >= 0 && code <= 65535) {

src/transaction.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ int Transaction::addRequestHeader(const std::string& key,
527527

528528
// find the first '='
529529
pos = c.find_first_of("=", 0);
530-
std::string ckey = "";
530+
std::string ckey;
531531
std::string cval = "";
532532

533533
// if the cookie doesn't contains '=', its just a key

src/unique_id.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ std::string UniqueId::ethernetMacAddress() {
229229

230230
return std::string(reinterpret_cast<const char *>(mac));
231231
#if defined(__linux__) || defined(__gnu_linux__) || defined(DARWIN) || defined(WIN32)
232-
failed:
232+
failed: // cppcheck-suppress unusedLabelConfiguration
233233
return std::string("");
234234
#endif
235235
}

0 commit comments

Comments
 (0)