Skip to content

Commit 2ec640f

Browse files
committed
Delete unused copy constructor & assignment operator in Rule, RuleMarker & Action
- Declare other unsupported copy constructor & assignment operators as deleted too (RuleWithActions, RuleUnconditional & RuleScript)
1 parent f180e64 commit 2ec640f

File tree

7 files changed

+40
-150
lines changed

7 files changed

+40
-150
lines changed

headers/modsecurity/actions/action.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,9 @@ class Action {
8181
set_name_and_payload(_action);
8282
}
8383

84-
Action(const Action &a)
85-
: m_isNone(a.m_isNone),
86-
temporaryAction(a.temporaryAction),
87-
action_kind(a.action_kind),
88-
m_name(a.m_name),
89-
m_parser_payload(a.m_parser_payload) { }
90-
91-
Action &operator=(const Action& a) {
92-
m_isNone = a.m_isNone;
93-
temporaryAction = a.temporaryAction;
94-
action_kind = a.action_kind;
95-
m_name = a.m_name;
96-
m_parser_payload = a.m_parser_payload;
97-
return *this;
98-
}
84+
Action(const Action &a) = delete;
85+
86+
Action &operator=(const Action& a) = delete;
9987

10088
virtual ~Action() { }
10189

headers/modsecurity/rule.h

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@
1313
*
1414
*/
1515

16-
#ifdef __cplusplus
17-
#include <stack>
18-
#include <vector>
19-
#include <string>
20-
#include <list>
21-
#include <memory>
22-
#include <utility>
23-
#endif
24-
2516
#ifndef HEADERS_MODSECURITY_RULE_H_
2617
#define HEADERS_MODSECURITY_RULE_H_
2718

@@ -31,6 +22,12 @@
3122

3223
#ifdef __cplusplus
3324

25+
#include <vector>
26+
#include <string>
27+
#include <list>
28+
#include <memory>
29+
#include <utility>
30+
3431
namespace modsecurity {
3532
namespace variables {
3633
class Variable;
@@ -73,18 +70,9 @@ class Rule {
7370
m_phase(modsecurity::Phases::RequestHeadersPhase) {
7471
}
7572

76-
Rule(const Rule &other) :
77-
m_fileName(other.m_fileName),
78-
m_lineNumber(other.m_lineNumber),
79-
m_phase(other.m_phase)
80-
{ }
81-
82-
Rule &operator=(const Rule& other) {
83-
m_fileName = other.m_fileName;
84-
m_lineNumber = other.m_lineNumber;
85-
m_phase = other.m_phase;
86-
return *this;
87-
}
73+
Rule(const Rule &other) = delete;
74+
75+
Rule &operator=(const Rule &other) = delete;
8876

8977
virtual ~Rule() {}
9078

headers/modsecurity/rule_marker.h

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@
1313
*
1414
*/
1515

16-
#ifdef __cplusplus
17-
#include <stack>
18-
#include <vector>
19-
#include <string>
20-
#include <list>
21-
#include <memory>
22-
#include <utility>
23-
#endif
24-
2516
#ifndef HEADERS_MODSECURITY_RULE_MARKER_H_
2617
#define HEADERS_MODSECURITY_RULE_MARKER_H_
2718

@@ -32,6 +23,9 @@
3223

3324
#ifdef __cplusplus
3425

26+
#include <string>
27+
#include <memory>
28+
3529
namespace modsecurity {
3630

3731

@@ -42,45 +36,32 @@ class RuleMarker : public Rule {
4236
std::unique_ptr<std::string> fileName,
4337
int lineNumber)
4438
: Rule(std::move(fileName), lineNumber),
45-
m_name(std::make_shared<std::string>(name)) { }
46-
47-
RuleMarker(const RuleMarker& r) :
48-
Rule(r),
49-
m_name(r.m_name)
50-
{ }
39+
m_name(name) { }
5140

52-
RuleMarker &operator =(const RuleMarker& r) {
53-
Rule::operator = (r);
54-
m_name = r.m_name;
55-
return *this;
56-
}
41+
RuleMarker(const RuleMarker &r) = delete;
5742

43+
RuleMarker &operator=(const RuleMarker &r) = delete;
44+
5845
virtual bool evaluate(Transaction *transaction,
5946
std::shared_ptr<RuleMessage> rm) override {
6047
return evaluate(transaction);
6148
}
6249

6350
virtual bool evaluate(Transaction *transaction) override {
64-
if (transaction->isInsideAMarker()) {
65-
if (*transaction->getCurrentMarker() == *m_name) {
51+
if (transaction->isInsideAMarker() &&
52+
*transaction->getCurrentMarker() == m_name) {
6653
transaction->removeMarker();
6754
// FIXME: Move this to .cc
6855
// ms_dbg_a(transaction, 4, "Out of a SecMarker " + *m_name);
69-
}
7056
}
7157

7258
return true;
7359
};
7460

75-
76-
std::shared_ptr<std::string> getName() {
77-
return m_name;
78-
}
79-
8061
bool isMarker() override { return true; }
8162

8263
private:
83-
std::shared_ptr<std::string> m_name;
64+
const std::string m_name;
8465
};
8566

8667

headers/modsecurity/rule_unconditional.h

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@
1313
*
1414
*/
1515

16-
#ifdef __cplusplus
17-
#include <stack>
18-
#include <vector>
19-
#include <string>
20-
#include <list>
21-
#include <memory>
22-
#include <utility>
23-
#endif
24-
2516
#ifndef HEADERS_MODSECURITY_RULE_UNCONDITIONAL_H_
2617
#define HEADERS_MODSECURITY_RULE_UNCONDITIONAL_H_
2718

@@ -34,30 +25,18 @@
3425

3526
#ifdef __cplusplus
3627

28+
#include <vector>
29+
#include <string>
30+
#include <memory>
31+
3732
namespace modsecurity {
3833

3934

4035
class RuleUnconditional : public RuleWithActions {
4136
public:
42-
RuleUnconditional(
43-
std::vector<actions::Action *> *actions,
44-
Transformations *transformations,
45-
std::unique_ptr<std::string> fileName,
46-
int lineNumber)
47-
: RuleWithActions(actions, transformations, std::move(fileName), lineNumber) { }
48-
49-
RuleUnconditional(const RuleUnconditional& r)
50-
: RuleWithActions(r)
51-
{ }
52-
53-
RuleUnconditional &operator=(const RuleUnconditional& r) {
54-
RuleWithActions::operator = (r);
55-
return *this;
56-
}
37+
using RuleWithActions::RuleWithActions;
5738

5839
virtual bool evaluate(Transaction *transaction, std::shared_ptr<RuleMessage> ruleMessage) override;
59-
60-
private:
6140
};
6241

6342

headers/modsecurity/rule_with_actions.h

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -43,63 +43,15 @@ class RuleWithActions : public Rule {
4343
std::unique_ptr<std::string> fileName,
4444
int lineNumber);
4545

46-
~RuleWithActions();
47-
48-
RuleWithActions(const RuleWithActions& r)
49-
: Rule(r),
50-
m_rev(r.m_rev),
51-
m_ver(r.m_ver),
52-
m_accuracy(r.m_accuracy),
53-
m_maturity(r.m_maturity),
54-
m_ruleId(r.m_ruleId),
55-
m_chainedRuleChild(r.m_chainedRuleChild),
56-
m_chainedRuleParent(r.m_chainedRuleParent),
57-
m_disruptiveAction(r.m_disruptiveAction),
58-
m_logData(r.m_logData),
59-
m_msg(r.m_msg),
60-
m_severity(r.m_severity),
61-
m_actionsRuntimePos(r.m_actionsRuntimePos),
62-
m_actionsSetVar(r.m_actionsSetVar),
63-
m_actionsTag(r.m_actionsTag),
64-
m_transformations(r.m_transformations),
65-
m_containsCaptureAction(r.m_containsCaptureAction),
66-
m_containsMultiMatchAction(r.m_containsMultiMatchAction),
67-
m_containsStaticBlockAction(r.m_containsStaticBlockAction),
68-
m_isChained(r.m_isChained)
69-
{ }
70-
71-
RuleWithActions &operator=(const RuleWithActions& r) {
72-
Rule::operator = (r);
73-
m_rev = r.m_rev;
74-
m_ver = r.m_ver;
75-
m_accuracy = r.m_accuracy;
76-
m_maturity = r.m_maturity;
77-
m_ruleId = r.m_ruleId;
78-
m_chainedRuleChild = r.m_chainedRuleChild;
79-
m_chainedRuleParent = r.m_chainedRuleParent;
80-
81-
m_disruptiveAction = r.m_disruptiveAction;
82-
m_logData = r.m_logData;
83-
m_msg = r.m_msg;
84-
m_severity = r.m_severity;
85-
m_actionsRuntimePos = r.m_actionsRuntimePos;
86-
m_actionsSetVar = r.m_actionsSetVar;
87-
m_actionsTag = r.m_actionsTag;
88-
89-
m_transformations = r.m_transformations;
90-
91-
m_containsCaptureAction = r.m_containsCaptureAction;
92-
m_containsMultiMatchAction = r.m_containsMultiMatchAction;
93-
m_containsStaticBlockAction = r.m_containsStaticBlockAction;
94-
m_isChained = r.m_isChained;
95-
96-
return *this;
97-
}
46+
~RuleWithActions() override;
9847

99-
virtual bool evaluate(Transaction *transaction, std::shared_ptr<RuleMessage> ruleMessage) override;
48+
RuleWithActions(const RuleWithActions &r) = delete;
49+
50+
RuleWithActions &operator=(const RuleWithActions &r) = delete;
10051

10152
virtual bool evaluate(Transaction *transaction) override;
10253

54+
virtual bool evaluate(Transaction *transaction, std::shared_ptr<RuleMessage> ruleMessage) override;
10355

10456
void executeActionsIndependentOfChainedRuleResult(
10557
Transaction *trasn,

headers/modsecurity/rule_with_operator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class RuleWithOperator : public RuleWithActions {
4545
std::unique_ptr<std::string> fileName,
4646
int lineNumber);
4747

48-
virtual ~RuleWithOperator();
48+
~RuleWithOperator() override;
4949

5050
bool evaluate(Transaction *transaction,
5151
std::shared_ptr<RuleMessage> rm) override;

src/rule_script.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
*
1515
*/
1616

17+
#ifndef SRC_RULE_SCRIPT_H_
18+
#define SRC_RULE_SCRIPT_H_
19+
1720
#include <string>
1821
#include <memory>
1922
#include <vector>
@@ -33,9 +36,6 @@
3336
#include "src/actions/severity.h"
3437
#include "src/variables/variable.h"
3538

36-
#ifndef SRC_RULE_SCRIPT_H_
37-
#define SRC_RULE_SCRIPT_H_
38-
3939

4040
namespace modsecurity {
4141

@@ -53,13 +53,15 @@ class RuleScript : public RuleWithActions {
5353
m_name(name),
5454
m_lua() { }
5555

56-
RuleScript(const RuleWithActions& r) = delete;
56+
RuleScript(const RuleScript& r) = delete;
57+
58+
RuleScript &operator=(const RuleScript &r) = delete;
5759

5860
bool init(std::string *err);
61+
5962
bool evaluate(Transaction *trans,
6063
std::shared_ptr<RuleMessage> ruleMessage) override;
6164

62-
6365
std::string m_name;
6466
engine::Lua m_lua;
6567
};

0 commit comments

Comments
 (0)