Skip to content

Commit

Permalink
Fix rules dump
Browse files Browse the repository at this point in the history
The unique pointer for file name was being used multiple times
on SecMarker.
  • Loading branch information
zimmerle committed Feb 4, 2021
1 parent 6ca028b commit 50fc347
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
7 changes: 5 additions & 2 deletions headers/modsecurity/rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ using MatchActions = std::vector<actions::Action *>;
class Rule {
public:
Rule(std::unique_ptr<std::string> fileName, int lineNumber)
: m_fileName(std::move(fileName)),
: m_fileName(std::make_shared<std::string>(*fileName)),
m_lineNumber(lineNumber),
m_phase(modsecurity::Phases::RequestHeadersPhase) {
}
Expand Down Expand Up @@ -103,7 +103,10 @@ class Rule {
void setPhase(int phase) { m_phase = phase; }

virtual std::string getReference() {
return *m_fileName + ":" + std::to_string(m_lineNumber);
if (m_fileName) {
return *m_fileName + ":" + std::to_string(m_lineNumber);
}
return "<<no file>>:" + std::to_string(m_lineNumber);
}


Expand Down
10 changes: 10 additions & 0 deletions headers/modsecurity/rule_marker.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ class RuleMarker : public Rule {
: Rule(std::move(fileName), lineNumber),
m_name(std::make_shared<std::string>(name)) { }

RuleMarker(const RuleMarker& r) :
Rule(r),
m_name(r.m_name)
{ }

RuleMarker &operator =(const RuleMarker& r) {
Rule::operator = (r);
m_name = r.m_name;
return *this;
}

virtual bool evaluate(Transaction *transaction,
std::shared_ptr<RuleMessage> rm) override {
Expand Down
9 changes: 9 additions & 0 deletions headers/modsecurity/rule_unconditional.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ class RuleUnconditional : public RuleWithActions {
int lineNumber)
: RuleWithActions(actions, transformations, std::move(fileName), lineNumber) { }

RuleUnconditional(const RuleUnconditional& r)
: RuleWithActions(r)
{ }

RuleUnconditional &operator=(const RuleUnconditional& r) {
RuleWithActions::operator = (r);
return *this;
}

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

private:
Expand Down
4 changes: 2 additions & 2 deletions src/parser/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Driver::~Driver() {
int Driver::addSecMarker(std::string marker, std::unique_ptr<std::string> fileName, int lineNumber) {
// FIXME: we might move this to the parser.
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
RuleMarker *r = new RuleMarker(marker, std::move(fileName), lineNumber);
std::unique_ptr<RuleMarker> rule(std::move(r));
RuleMarker *r = new RuleMarker(marker, std::unique_ptr<std::string>(new std::string(*fileName)), lineNumber);
std::unique_ptr<RuleMarker> rule(r);
rule->setPhase(i);
m_rulesSetPhases.insert(std::move(rule));
}
Expand Down
2 changes: 2 additions & 0 deletions src/rule_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class RuleScript : public RuleWithActions {
m_name(name),
m_lua() { }

RuleScript(const RuleWithActions& r) = delete;

bool init(std::string *err);
bool evaluate(Transaction *trans,
std::shared_ptr<RuleMessage> ruleMessage) override;
Expand Down

0 comments on commit 50fc347

Please sign in to comment.