Skip to content

Commit 61c4319

Browse files
committed
Action: make sure that null constructor is not used
1 parent e9adb6c commit 61c4319

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

headers/modsecurity/actions/action.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include <string>
1919

20+
#include <assert.h>
21+
2022
#endif
2123

2224

@@ -35,7 +37,9 @@ class Action {
3537
Action()
3638
: m_parserPayload(""),
3739
m_name("")
38-
{ }
40+
{
41+
assert(0);
42+
}
3943

4044

4145
explicit Action(const std::string& action)
@@ -44,9 +48,9 @@ class Action {
4448
{ }
4549

4650

47-
Action(const Action &a)
48-
: m_parserPayload(a.m_parserPayload),
49-
m_name(a.m_name)
51+
Action(const Action &other)
52+
: m_parserPayload(other.m_parserPayload),
53+
m_name(other.m_name)
5054
{ }
5155

5256

@@ -76,7 +80,7 @@ class Action {
7680
}
7781

7882

79-
const std::string *getName() const {
83+
const std::string *getName() const noexcept {
8084
return &m_name;
8185
}
8286

src/actions/transformations/transformation.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,23 @@ namespace actions {
6565
namespace transformations {
6666

6767

68-
class TransformationDoesNotExist: public std::exception {
68+
class TransformationDoesNotExist : public std::exception {
6969
public:
70+
explicit TransformationDoesNotExist(const char *name)
71+
: m_transformation(name)
72+
{ }
73+
7074
explicit TransformationDoesNotExist(const std::string& name)
7175
: m_transformation(name)
7276
{ }
7377

74-
virtual const char* what() const throw() {
75-
return std::string("Transformation not found: " + m_transformation + \
76-
". Make sure that the new transformation is registered at: " + \
77-
"transformation.cc").c_str();
78-
}
78+
virtual ~TransformationDoesNotExist() throw (){}
79+
80+
virtual const char* what() const throw() {
81+
return strdup(std::string("Transformation not found: " + m_transformation + \
82+
". Make sure that the new transformation is registered at: " + \
83+
"transformation.cc").c_str());
84+
}
7985

8086
private:
8187
std::string m_transformation;

src/actions/transformations/trim_left.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace transformations {
3434
class TrimLeft : public Trim {
3535
public:
3636
TrimLeft()
37-
: Trim("t:trimLeft")
37+
: Action("t:trimLeft")
3838
{ }
3939

4040
void execute(const Transaction *t,

src/actions/transformations/trim_right.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace transformations {
3434
class TrimRight : public Trim {
3535
public:
3636
TrimRight()
37-
: Trim("t:trimRight")
37+
: Action("t:trimRight")
3838
{ }
3939

4040
void execute(const Transaction *t,

0 commit comments

Comments
 (0)