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

Lines changed: 8 additions & 7 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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);

0 commit comments

Comments
 (0)