Skip to content

Commit fe98ce4

Browse files
committed
Cosmetics: address cppcheck warnings
1 parent 68ef2de commit fe98ce4

Some content is hidden

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

53 files changed

+354
-275
lines changed

Makefile.am

+11-9
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,17 @@ parser:
5656

5757

5858
cppcheck:
59-
@cppcheck -U YYSTYPE \
60-
--suppressions-list=./test/cppcheck_suppressions.txt \
61-
--enable=all \
62-
--inconclusive \
63-
--template="warning: {file},{line},{severity},{id},{message}" \
64-
-I headers -I . -I others -I src -I others/mbedtls -I src/parser \
65-
--error-exitcode=0 \
66-
-i "src/parser/seclang-parser.cc" -i "src/parser/seclang-scanner.cc" \
67-
.
59+
@cppcheck -U YYSTYPE -U MBEDTLS_MD5_ALT -U MBEDTLS_SHA1_ALT \
60+
-D MS_CPPCHECK_DISABLED_FOR_PARSER \
61+
--suppressions-list=./test/cppcheck_suppressions.txt \
62+
--enable=all \
63+
--inconclusive \
64+
--template="warning: {file},{line},{severity},{id},{message}" \
65+
-I headers -I . -I others -I src -I others/mbedtls -I src/parser \
66+
--error-exitcode=1 \
67+
-i "src/parser/seclang-parser.cc" -i "src/parser/seclang-scanner.cc" \
68+
--force --verbose .
69+
6870

6971
check-static: cppcheck
7072

build/lua.m4

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ AC_DEFUN([CHECK_LUA],
66
[dnl
77
88
# Possible names for the lua library/package (pkg-config)
9-
LUA_POSSIBLE_LIB_NAMES="luajit luajit-5.1 lua53 lua5.3 lua-5.3 lua52 lua5.2 lua-5.2 lua51 lua5.1 lua-5.1 lua"
9+
LUA_POSSIBLE_LIB_NAMES="lua53 lua5.3 lua-5.3 lua52 lua5.2 lua-5.2 lua51 lua5.1 lua-5.1 lua"
1010
1111
# Possible extensions for the library
1212
LUA_POSSIBLE_EXTENSIONS="so so0 la sl dll dylib so.0.0.0"

examples/reading_logs_via_rule_message/reading_logs_via_rule_message.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class ReadingLogsViaRuleMessage {
115115
char *response_headers,
116116
char *response_body,
117117
char *ip,
118-
std::string rules) :
118+
const std::string &rules) :
119119
m_request_header(request_header),
120120
m_request_uri(request_uri),
121121
m_request_body(request_body),
@@ -133,7 +133,6 @@ class ReadingLogsViaRuleMessage {
133133

134134
modsecurity::ModSecurity *modsec;
135135
modsecurity::Rules *rules;
136-
modsecurity::ModSecurityIntervention it;
137136

138137
modsec = new modsecurity::ModSecurity();
139138
modsec->setConnectorInformation("ModSecurity-test v0.0.1-alpha" \
@@ -168,8 +167,6 @@ class ReadingLogsViaRuleMessage {
168167
delete modsec;
169168
pthread_exit(NULL);
170169
return 0;
171-
end:
172-
return -1;
173170
}
174171

175172
static void logCb(void *data, const void *ruleMessagev) {

examples/using_bodies_in_chunks/simple_request.cc

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ int process_intervention(modsecurity::Transaction *transaction) {
126126
int main(int argc, char **argv) {
127127
modsecurity::ModSecurity *modsec;
128128
modsecurity::Rules *rules;
129-
modsecurity::ModSecurityIntervention it;
130129

131130
if (argc < 2) {
132131
std::cout << "Use " << *argv << " test-case-file.conf";

headers/modsecurity/anchored_set_variable.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct MyHash{
7171
class AnchoredSetVariable : public std::unordered_multimap<std::string,
7272
VariableValue *, MyHash, MyEqual> {
7373
public:
74-
AnchoredSetVariable(Transaction *t, std::string name);
74+
AnchoredSetVariable(Transaction *t, const std::string &name);
7575
~AnchoredSetVariable();
7676

7777
void unset();

headers/modsecurity/anchored_variable.h

+12-9
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,18 @@ class Transaction;
4242

4343
class AnchoredVariable {
4444
public:
45-
AnchoredVariable(Transaction* t, std::string name);
46-
47-
AnchoredVariable(const AnchoredVariable &a) {
48-
m_transaction = a.m_transaction;
49-
m_offset = a.m_offset;
50-
m_name = a.m_name;
51-
m_value = a.m_value;
52-
m_var = a.m_var;
53-
}
45+
AnchoredVariable(Transaction* t, const std::string &name);
46+
47+
AnchoredVariable(const AnchoredVariable &a) = delete;
48+
AnchoredVariable &operator= (const AnchoredVariable &a) = delete;
49+
50+
/*
51+
: m_transaction(a.m_transaction),
52+
m_offset(a.m_offset),
53+
m_name(a.m_name),
54+
m_value(a.m_value),
55+
m_var(a.m_var) { }
56+
*/
5457

5558
~AnchoredVariable();
5659

headers/modsecurity/audit_log.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class Writer;
3737
class AuditLog {
3838
public:
3939
AuditLog();
40-
~AuditLog();
40+
virtual ~AuditLog();
41+
42+
AuditLog(const AuditLog &a) = delete;
4143

4244
enum AuditLogType {
4345
NotSetAuditLogType,
@@ -158,22 +160,22 @@ class AuditLog {
158160
bool setStorageDir(const std::basic_string<char>& path);
159161
bool setFormat(AuditLogFormat fmt);
160162

161-
int getDirectoryPermission();
162-
int getFilePermission();
163-
int getParts();
163+
int getDirectoryPermission() const;
164+
int getFilePermission() const;
165+
int getParts() const;
164166

165167
bool setParts(const std::basic_string<char>& new_parts);
166168
bool setType(AuditLogType audit_type);
167169

168170
bool init(std::string *error);
169-
bool close();
171+
virtual bool close();
170172

171173
bool saveIfRelevant(Transaction *transaction);
172174
bool saveIfRelevant(Transaction *transaction, int parts);
173175
bool isRelevant(int status);
174176

175-
int addParts(int parts, const std::string& new_parts);
176-
int removeParts(int parts, const std::string& new_parts);
177+
static int addParts(int parts, const std::string& new_parts);
178+
static int removeParts(int parts, const std::string& new_parts);
177179

178180
bool merge(AuditLog *from, std::string *error);
179181

headers/modsecurity/collection/collection.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace collection {
4444

4545
class Collection {
4646
public:
47-
explicit Collection(std::string a) : m_name(a) { }
47+
explicit Collection(const std::string &a) : m_name(a) { }
4848
virtual ~Collection() { }
4949
virtual void store(std::string key, std::string value) = 0;
5050

headers/modsecurity/collection/collections.h

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class Collections {
4949
Collection *user, Collection *resource);
5050
~Collections();
5151

52+
Collections(const Collections &c) = delete;
53+
Collections& operator =(const Collections &c) = delete;
54+
5255
std::string m_global_collection_key;
5356
std::string m_ip_collection_key;
5457
std::string m_session_collection_key;

headers/modsecurity/debug_log.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ class DebugLog {
4343
virtual void write(int level, const std::string &msg);
4444
virtual void write(int level, const std::string &id,
4545
const std::string &uri, const std::string &msg);
46-
bool isLogFileSet();
47-
bool isLogLevelSet();
48-
void setDebugLogLevel(int level);
49-
void setDebugLogFile(const std::string &fileName, std::string *error);
50-
const std::string& getDebugLogFile();
46+
virtual bool isLogFileSet();
47+
virtual bool isLogLevelSet();
48+
virtual void setDebugLogLevel(int level);
49+
virtual void setDebugLogFile(const std::string &fileName, std::string *error);
50+
virtual const std::string& getDebugLogFile();
5151
virtual int getDebugLogLevel();
5252

5353
int m_debugLevel;

headers/modsecurity/modsecurity.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,11 @@ class ModSecurity {
278278
ModSecurity();
279279
~ModSecurity();
280280

281+
ModSecurity(const ModSecurity &m) = delete;
282+
ModSecurity& operator= (const ModSecurity &m) = delete;
283+
281284
const std::string& whoAmI();
282-
void setConnectorInformation(std::string connector);
285+
void setConnectorInformation(const std::string &connector);
283286
void setServerLogCb(ModSecLogCb cb);
284287
/**
285288
*
@@ -291,9 +294,9 @@ class ModSecurity {
291294

292295
void serverLog(void *data, std::shared_ptr<RuleMessage> rm);
293296

294-
const std::string& getConnectorInformation();
297+
const std::string& getConnectorInformation() const;
295298

296-
int processContentOffset(const char *content, size_t len,
299+
static int processContentOffset(const char *content, size_t len,
297300
const char *matchString, std::string *json, const char **err);
298301

299302
collection::Collection *m_global_collection;

headers/modsecurity/rule.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Rule {
7474
std::list<std::pair<std::shared_ptr<std::string>,
7575
std::shared_ptr<std::string>>> *ret,
7676
std::string *path,
77-
int *nth);
77+
int *nth) const;
7878

7979
void getVariablesExceptions(Transaction *t,
8080
variables::Variables *exclusion, variables::Variables *addition);
@@ -91,9 +91,9 @@ class Rule {
9191
std::string value, std::shared_ptr<RuleMessage> rm);
9292
void executeActionsIndependentOfChainedRuleResult(Transaction *trasn,
9393
bool *b, std::shared_ptr<RuleMessage> ruleMessage);
94-
inline void updateMatchedVars(Transaction *trasn, const std::string &key,
94+
static inline void updateMatchedVars(Transaction *trasn, const std::string &key,
9595
const std::string &value);
96-
inline void cleanMatchedVars(Transaction *trasn);
96+
static inline void cleanMatchedVars(Transaction *trasn);
9797

9898
std::vector<actions::Action *> getActionsByName(const std::string& name,
9999
Transaction *t);

headers/modsecurity/rule_message.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,25 @@ class RuleMessage {
6767

6868

6969
std::string log() {
70-
return RuleMessage::log(this, 0);
70+
return log(this, 0);
7171
}
7272
std::string log(int props) {
73-
return RuleMessage::log(this, props);
73+
return log(this, props);
7474
}
7575
std::string log(int props, int responseCode) {
76-
return RuleMessage::log(this, props, responseCode);
76+
return log(this, props, responseCode);
7777
}
7878
std::string errorLog() {
79-
return RuleMessage::log(this,
79+
return log(this,
8080
ClientLogMessageInfo | ErrorLogTailLogMessageInfo);
8181
}
8282

8383
static std::string log(const RuleMessage *rm, int props, int code);
8484
static std::string log(const RuleMessage *rm, int props) {
85-
return RuleMessage::log(rm, props, -1);
85+
return log(rm, props, -1);
8686
}
8787
static std::string log(const RuleMessage *rm) {
88-
return RuleMessage::log(rm, 0);
88+
return log(rm, 0);
8989
}
9090

9191
static std::string _details(const RuleMessage *rm);

headers/modsecurity/rules.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Rules : public RulesProperties {
7070
int load(const char *rules);
7171
int load(const char *rules, const std::string &ref);
7272

73-
void dump();
73+
void dump() const;
7474

7575
int merge(Parser::Driver *driver);
7676
int merge(Rules *rules);
@@ -84,10 +84,10 @@ class Rules : public RulesProperties {
8484
int64_t unicode_codepage;
8585

8686
private:
87-
int m_referenceCount;
8887
#ifndef NO_LOGS
8988
uint8_t m_secmarker_skipped;
9089
#endif
90+
int m_referenceCount;
9191
};
9292

9393
#endif

headers/modsecurity/rules_properties.h

+2
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ class RulesProperties {
197197
m_remoteRulesActionOnFailed(PropertyNotSetRemoteRulesAction),
198198
m_secRuleEngine(PropertyNotSetRuleEngine) { }
199199

200+
RulesProperties(const RulesProperties &r) = delete;
201+
RulesProperties &operator =(const RulesProperties &r) = delete;
200202

201203
~RulesProperties() {
202204
int i = 0;

headers/modsecurity/transaction.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class Transaction : public TransactionAnchoredVariables {
295295

296296
Transaction ( const Transaction & ) = delete;
297297
bool operator ==(const Transaction &b) const { return false; };
298-
Transaction operator =(const Transaction &b) const = delete;
298+
Transaction &operator =(const Transaction &b) const = delete;
299299

300300
/** TODO: Should be an structure that fits an IP address */
301301
int processConnection(const char *client, int cPort,
@@ -359,7 +359,7 @@ class Transaction : public TransactionAnchoredVariables {
359359
bool extractArguments(const std::string &orig, const std::string& buf,
360360
size_t offset);
361361

362-
const char *getResponseBody();
362+
const char *getResponseBody() const;
363363
size_t getResponseBodyLength();
364364
size_t getRequestBodyLength();
365365

@@ -368,7 +368,7 @@ class Transaction : public TransactionAnchoredVariables {
368368
#endif
369369
void serverLog(std::shared_ptr<RuleMessage> rm);
370370

371-
int getRuleEngineState();
371+
int getRuleEngineState() const;
372372

373373
std::string toJSON(int parts);
374374
std::string toOldAuditLogFormat(int parts, const std::string &trailer);

headers/modsecurity/variable_value.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,28 @@ class VariableValue {
3939
public:
4040
using Origins = std::list<std::unique_ptr<VariableOrigin>>;
4141

42-
VariableValue(const std::string *key,
42+
explicit VariableValue(const std::string *key,
4343
const std::string *value = nullptr)
44-
: m_key(*key),
44+
: m_collection(""),
45+
m_key(*key),
4546
m_keyWithCollection(*key),
46-
m_collection(""),
4747
m_value(value != nullptr?*value:"")
4848
{ }
4949

5050
VariableValue(const std::string *collection,
5151
const std::string *key,
5252
const std::string *value)
53-
: m_key(*key),
53+
: m_collection(*collection),
54+
m_key(*key),
5455
m_keyWithCollection(*collection + ":" + *key),
55-
m_collection(*collection),
5656
m_value(*value)
5757
{ }
5858

5959
explicit VariableValue(const VariableValue *o) :
60-
m_key(o->m_key),
61-
m_value(o->m_value),
6260
m_collection(o->m_collection),
63-
m_keyWithCollection(o->m_keyWithCollection)
61+
m_key(o->m_key),
62+
m_keyWithCollection(o->m_keyWithCollection),
63+
m_value(o->m_value)
6464
{
6565
for (auto &i : o->m_orign) {
6666
std::unique_ptr<VariableOrigin> origin(new VariableOrigin());
@@ -70,6 +70,8 @@ class VariableValue {
7070
}
7171
}
7272

73+
VariableValue(const VariableValue &v) = delete;
74+
7375

7476
const std::string& getKey() const {
7577
return m_key;

src/anchored_set_variable.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
namespace modsecurity {
2929

3030

31-
AnchoredSetVariable::AnchoredSetVariable(Transaction *t, std::string name)
31+
AnchoredSetVariable::AnchoredSetVariable(Transaction *t,
32+
const std::string &name)
3233
: m_transaction(t),
3334
m_name(name) {
3435
reserve(10);

src/anchored_variable.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace modsecurity {
2828

2929

3030
AnchoredVariable::AnchoredVariable(Transaction *t,
31-
std::string name)
31+
const std::string &name)
3232
: m_transaction(t),
3333
m_offset(0),
3434
m_name(""),

0 commit comments

Comments
 (0)