Skip to content

Commit 29a86b1

Browse files
authored
Merge pull request #3283 from eduar-hte/cppcheck2142
Use latest version of cppcheck (2.15.0) to analyze codebase
2 parents ec506da + aca93f5 commit 29a86b1

Some content is hidden

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

77 files changed

+210
-297
lines changed

.github/workflows/ci.yml

+8-7
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,21 @@ jobs:
178178
ctest -C ${{ matrix.configuration }} --output-on-failure
179179
180180
cppcheck:
181-
runs-on: [ubuntu-22.04]
181+
runs-on: [macos-14]
182182
steps:
183183
- name: Setup Dependencies
184184
run: |
185-
sudo apt-get update -y -qq
186-
sudo apt-get install -y cppcheck
187-
- name: Checkout source
188-
uses: actions/checkout@v4
185+
brew install autoconf \
186+
automake \
187+
libtool \
188+
cppcheck
189+
- uses: actions/checkout@v4
189190
with:
190191
submodules: true
191192
fetch-depth: 0
192-
- name: Configure libModSecurity
193+
- name: configure
193194
run: |
194195
./build.sh
195196
./configure
196-
- name: Run cppcheck on libModSecurity
197+
- name: cppcheck
197198
run: make check-static

Makefile.am

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ cppcheck:
6363
--enable=warning,style,performance,portability,unusedFunction,missingInclude \
6464
--inconclusive \
6565
--template="warning: {file},{line},{severity},{id},{message}" \
66-
-I headers -I . -I others -I src -I others/mbedtls/include -I src/parser \
66+
-I headers -I . -I others -I src -I others/mbedtls/include \
6767
--error-exitcode=1 \
6868
-i "src/parser/seclang-parser.cc" -i "src/parser/seclang-scanner.cc" \
69+
-i others \
70+
--std=c++17 \
6971
--force --verbose .
7072

7173

examples/multithread/multithread.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int main (int argc, char *argv[]) {
4040
modsec->setConnectorInformation("ModSecurity-test v0.0.1-alpha (Simple " \
4141
"example on how to use ModSecurity API");
4242

43-
char main_rule_uri[] = "basic_rules.conf";
43+
const char main_rule_uri[] = "basic_rules.conf";
4444
auto rules = std::make_unique<modsecurity::RulesSet>();
4545
if (rules->loadFromUri(main_rule_uri) < 0) {
4646
std::cerr << "Problems loading the rules..." << std::endl;

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_with_actions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class RuleWithActions : public Rule {
7979
bool chainedParentNull = false) const;
8080

8181
std::vector<actions::Action *> getActionsByName(const std::string& name,
82-
Transaction *t);
82+
const Transaction *t);
8383
bool containsTag(const std::string& name, Transaction *t);
8484
bool containsMsg(const std::string& name, Transaction *t);
8585

headers/modsecurity/rule_with_operator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class RuleWithOperator : public RuleWithActions {
6262
static void cleanMatchedVars(Transaction *trasn);
6363

6464

65-
std::string getOperatorName() const;
65+
const std::string& getOperatorName() const;
6666

6767
virtual std::string getReference() override {
6868
return std::to_string(m_ruleId);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ class Transaction : public TransactionAnchoredVariables, public TransactionSecMa
405405
size_t getRequestBodyLength();
406406

407407
#ifndef NO_LOGS
408-
void debug(int, const std::string &) const; // cppcheck-suppress functionStatic
408+
void debug(int, const std::string &) const;
409409
#endif
410410
void serverLog(const RuleMessage &rm);
411411

@@ -713,7 +713,7 @@ int msc_process_uri(Transaction *transaction, const char *uri,
713713
const char *protocol, const char *http_version);
714714

715715
/** @ingroup ModSecurity_C_API */
716-
const char *msc_get_response_body(Transaction *transaction);
716+
const char *msc_get_response_body(const Transaction *transaction);
717717

718718
/** @ingroup ModSecurity_C_API */
719719
size_t msc_get_response_body_length(Transaction *transaction);

src/actions/ctl/rule_remove_by_id.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ bool RuleRemoveById::init(std::string *error) {
8484
}
8585

8686
bool RuleRemoveById::evaluate(RuleWithActions *rule, Transaction *transaction) {
87-
for (auto &i : m_ids) {
87+
for (const auto &i : m_ids) {
8888
transaction->m_ruleRemoveById.push_back(i);
8989
}
90-
for (auto &i : m_ranges) {
90+
for (const auto &i : m_ranges) {
9191
transaction->m_ruleRemoveByIdRange.push_back(i);
9292
}
9393

src/actions/exec.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ namespace actions {
3131
class Exec : public Action {
3232
public:
3333
explicit Exec(const std::string &action)
34-
: Action(action),
35-
m_script("") { }
36-
37-
~Exec() { }
34+
: Action(action) { }
3835

3936
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
4037
bool init(std::string *error) override;

src/actions/expire_var.cc

-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ namespace modsecurity {
3232
namespace actions {
3333

3434

35-
bool ExpireVar::init(std::string *error) {
36-
return true;
37-
}
38-
39-
4035
bool ExpireVar::evaluate(RuleWithActions *rule, Transaction *t) {
4136

4237
std::string expireExpressionExpanded(m_string->evaluate(t));

src/actions/expire_var.h

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class ExpireVar : public Action {
4040
m_string(std::move(z)) { }
4141

4242
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
43-
bool init(std::string *error) override;
4443

4544
private:
4645

src/actions/set_env.cc

-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ namespace modsecurity {
2626
namespace actions {
2727

2828

29-
bool SetENV::init(std::string *error) {
30-
return true;
31-
}
32-
33-
3429
bool SetENV::evaluate(RuleWithActions *rule, Transaction *t) {
3530
std::string colNameExpanded(m_string->evaluate(t));
3631

src/actions/set_env.h

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class SetENV : public Action {
4040
m_string(std::move(z)) { }
4141

4242
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
43-
bool init(std::string *error) override;
4443

4544
private:
4645
std::unique_ptr<RunTimeString> m_string;

src/actions/set_rsc.cc

-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ namespace modsecurity {
2626
namespace actions {
2727

2828

29-
bool SetRSC::init(std::string *error) {
30-
return true;
31-
}
32-
33-
3429
bool SetRSC::evaluate(RuleWithActions *rule, Transaction *t) {
3530
std::string colNameExpanded(m_string->evaluate(t));
3631
ms_dbg_a(t, 8, "RESOURCE initiated with value: \'"

src/actions/set_rsc.h

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class SetRSC : public Action {
4040
m_string(std::move(z)) { }
4141

4242
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
43-
bool init(std::string *error) override;
4443

4544
private:
4645
std::unique_ptr<RunTimeString> m_string;

src/actions/set_sid.cc

-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ namespace modsecurity {
2626
namespace actions {
2727

2828

29-
bool SetSID::init(std::string *error) {
30-
return true;
31-
}
32-
33-
3429
bool SetSID::evaluate(RuleWithActions *rule, Transaction *t) {
3530
std::string colNameExpanded(m_string->evaluate(t));
3631
ms_dbg_a(t, 8, "Session ID initiated with value: \'"

src/actions/set_sid.h

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class SetSID : public Action {
4040
m_string(std::move(z)) { }
4141

4242
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
43-
bool init(std::string *error) override;
4443

4544
private:
4645
std::unique_ptr<RunTimeString> m_string;

src/actions/set_uid.cc

-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ namespace modsecurity {
2626
namespace actions {
2727

2828

29-
bool SetUID::init(std::string *error) {
30-
return true;
31-
}
32-
33-
3429
bool SetUID::evaluate(RuleWithActions *rule, Transaction *t) {
3530
std::string colNameExpanded(m_string->evaluate(t));
3631
ms_dbg_a(t, 8, "User collection initiated with value: \'"

src/actions/set_uid.h

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class SetUID : public Action {
4040
m_string(std::move(z)) { }
4141

4242
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
43-
bool init(std::string *error) override;
4443

4544
private:
4645
std::unique_ptr<RunTimeString> m_string;

src/actions/set_var.cc

-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ namespace modsecurity {
3535
namespace actions {
3636

3737

38-
bool SetVar::init(std::string *error) {
39-
return true;
40-
}
41-
42-
4338
bool SetVar::evaluate(RuleWithActions *rule, Transaction *t) {
4439
std::string targetValue;
4540
std::string resolvedPre;

src/actions/set_var.h

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class SetVar : public Action {
5959
m_variable(std::move(variable)) { }
6060

6161
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
62-
bool init(std::string *error) override;
6362

6463
private:
6564
SetVarOperation m_operation;

src/actions/transformations/hex_decode.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static inline int inplace(std::string &value) {
2626

2727
const auto len = value.length();
2828
auto d = reinterpret_cast<unsigned char *>(value.data());
29-
const auto data = d;
29+
const auto *data = d;
3030

3131
for (int i = 0; i <= len - 2; i += 2) {
3232
*d++ = utils::string::x2c(&data[i]);

src/actions/transformations/html_entity_decode.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static inline bool inplace(std::string &value) {
118118
j++;
119119
}
120120
if (j > k) { /* Do we have at least one digit? */
121-
const auto x = reinterpret_cast<const char*>(&input[k]);
121+
const auto *x = reinterpret_cast<const char*>(&input[k]);
122122

123123
/* Decode the entity. */
124124
/* ENH What about others? */

src/actions/transformations/normalise_path.cc

+4-7
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ bool NormalisePath::transform(std::string &value, const Transaction *trans) cons
2929
* IMP1 Assumes NUL-terminated
3030
*/
3131
bool NormalisePath::normalize_path_inplace(std::string &val, const bool win) {
32-
unsigned char *src;
33-
unsigned char *dst;
34-
unsigned char *end;
3532
int hitroot = 0;
3633
int done = 0;
3734
int relative;
@@ -49,13 +46,13 @@ bool NormalisePath::normalize_path_inplace(std::string &val, const bool win) {
4946
* ENH: Deal with UNC and drive letters?
5047
*/
5148

52-
src = dst = input;
53-
end = input + (input_len - 1);
49+
auto src = input;
50+
auto dst = input;
51+
const auto *end = input + (input_len - 1);
5452

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

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

153150
/* Skip to the last forward slash when multiple are used. */
154151
if (*src == '/') {
155-
unsigned char *oldsrc = src;
152+
const unsigned char *oldsrc = src;
156153

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

src/actions/transformations/parity_zero_7bit.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations {
2222
static inline bool inplace(std::string &value) {
2323
if (value.empty()) return false;
2424

25-
for(auto &c : value) {
25+
for(auto &c : value) { // cppcheck-suppress constVariableReference ; false positive
2626
((unsigned char&)c) &= 0x7f;
2727
}
2828

src/actions/transformations/sql_hex_decode.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static inline bool inplace(std::string &value) {
3838

3939
auto d = reinterpret_cast<unsigned char*>(value.data());
4040
const unsigned char *data = d;
41-
const auto end = data + value.size();
41+
const auto *end = data + value.size();
4242

4343
bool changed = false;
4444

src/collection/backend/in_memory-per_process.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class InMemoryPerProcess :
7474
public Collection {
7575
public:
7676
explicit InMemoryPerProcess(const std::string &name);
77-
~InMemoryPerProcess();
77+
~InMemoryPerProcess() override;
7878
void store(const std::string &key, const std::string &value);
7979

8080
bool storeOrUpdateFirst(const std::string &key,

src/collection/backend/lmdb.cc

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

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

0 commit comments

Comments
 (0)