Skip to content

Commit

Permalink
Simplify initialization of fileName member of Rule instances
Browse files Browse the repository at this point in the history
  • Loading branch information
eduar-hte committed Sep 2, 2024
1 parent 5dac8ef commit b95abc9
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 28 deletions.
4 changes: 2 additions & 2 deletions headers/modsecurity/rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ using MatchActions = std::vector<actions::Action *>;

class Rule {
public:
Rule(std::unique_ptr<std::string> fileName, int lineNumber)
: m_fileName(*fileName),
Rule(const std::string &fileName, int lineNumber)
: m_fileName(fileName),
m_lineNumber(lineNumber),
m_phase(modsecurity::Phases::RequestHeadersPhase) {
}
Expand Down
4 changes: 2 additions & 2 deletions headers/modsecurity/rule_marker.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class RuleMarker : public Rule {
public:
RuleMarker(
const std::string &name,
std::unique_ptr<std::string> fileName,
const std::string &fileName,
int lineNumber)
: Rule(std::move(fileName), lineNumber),
: Rule(fileName, lineNumber),
m_name(name) { }

RuleMarker(const RuleMarker &r) = delete;
Expand Down
4 changes: 2 additions & 2 deletions headers/modsecurity/rule_unconditional.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class RuleUnconditional : public RuleWithActions {
RuleUnconditional(
std::vector<actions::Action *> *actions,
Transformations *transformations,
std::unique_ptr<std::string> fileName,
const std::string &fileName,
int lineNumber)
: RuleWithActions(actions, transformations, std::move(fileName), lineNumber) { }
: RuleWithActions(actions, transformations, fileName, lineNumber) { }

RuleUnconditional(const RuleUnconditional& r) = delete;

Expand Down
2 changes: 1 addition & 1 deletion headers/modsecurity/rule_with_actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RuleWithActions : public Rule {
RuleWithActions(
Actions *a,
Transformations *t,
std::unique_ptr<std::string> fileName,
const std::string &fileName,
int lineNumber);

virtual ~RuleWithActions();
Expand Down
2 changes: 1 addition & 1 deletion headers/modsecurity/rule_with_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RuleWithOperator : public RuleWithActions {
variables::Variables *variables,
std::vector<actions::Action *> *actions,
Transformations *transformations,
std::unique_ptr<std::string> fileName,
const std::string &fileName,
int lineNumber);

virtual ~RuleWithOperator();
Expand Down
5 changes: 2 additions & 3 deletions src/parser/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ Driver::~Driver() {
}


int Driver::addSecMarker(const std::string& marker, std::unique_ptr<std::string> fileName, int lineNumber) {
int Driver::addSecMarker(const std::string& marker, const 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::unique_ptr<std::string>(new std::string(*fileName)), lineNumber);
std::unique_ptr<RuleMarker> rule(r);
auto rule = std::make_unique<RuleMarker>(marker, fileName, lineNumber);
rule->setPhase(i);
m_rulesSetPhases.insert(std::move(rule));
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Driver : public RulesSetProperties {

int addSecRule(std::unique_ptr<RuleWithActions> rule);
int addSecAction(std::unique_ptr<RuleWithActions> rule);
int addSecMarker(const std::string& marker, std::unique_ptr<std::string> fileName, int lineNumber);
int addSecMarker(const std::string& marker, const std::string &fileName, int lineNumber);
int addSecRuleScript(std::unique_ptr<RuleScript> rule);

bool scan_begin();
Expand Down
10 changes: 5 additions & 5 deletions src/parser/seclang-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,7 @@ namespace yy {
/* variables */ v,
/* actions */ a,
/* transformations */ t,
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[3].location.end.filename)),
/* file name */ std::string(*yystack_[3].location.end.filename),
/* line number */ yystack_[3].location.end.line
));

Expand All @@ -2337,7 +2337,7 @@ namespace yy {
/* variables */ v,
/* actions */ NULL,
/* transformations */ NULL,
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[2].location.end.filename)),
/* file name */ std::string(*yystack_[2].location.end.filename),
/* line number */ yystack_[2].location.end.line
));
if (driver.addSecRule(std::move(rule)) == false) {
Expand All @@ -2363,7 +2363,7 @@ namespace yy {
std::unique_ptr<RuleUnconditional> rule(new RuleUnconditional(
/* actions */ a,
/* transformations */ t,
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[1].location.end.filename)),
/* file name */ std::string(*yystack_[1].location.end.filename),
/* line number */ yystack_[1].location.end.line
));
driver.addSecAction(std::move(rule));
Expand All @@ -2389,7 +2389,7 @@ namespace yy {
/* path to script */ yystack_[1].value.as < std::string > (),
/* actions */ a,
/* transformations */ t,
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[1].location.end.filename)),
/* file name */ std::string(*yystack_[1].location.end.filename),
/* line number */ yystack_[1].location.end.line
));

Expand Down Expand Up @@ -2469,7 +2469,7 @@ namespace yy {
#line 1241 "seclang-parser.yy"
{
driver.addSecMarker(modsecurity::utils::string::removeBracketsIfNeeded(yystack_[0].value.as < std::string > ()),
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[0].location.end.filename)),
/* file name */ std::string(*yystack_[0].location.end.filename),
/* line number */ yystack_[0].location.end.line
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/parser/seclang-parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ expression:
/* variables */ v,
/* actions */ a,
/* transformations */ t,
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
/* file name */ std::string(*@1.end.filename),
/* line number */ @1.end.line
));

Expand All @@ -1124,7 +1124,7 @@ expression:
/* variables */ v,
/* actions */ NULL,
/* transformations */ NULL,
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
/* file name */ std::string(*@1.end.filename),
/* line number */ @1.end.line
));
if (driver.addSecRule(std::move(rule)) == false) {
Expand All @@ -1146,7 +1146,7 @@ expression:
std::unique_ptr<RuleUnconditional> rule(new RuleUnconditional(
/* actions */ a,
/* transformations */ t,
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
/* file name */ std::string(*@1.end.filename),
/* line number */ @1.end.line
));
driver.addSecAction(std::move(rule));
Expand All @@ -1168,7 +1168,7 @@ expression:
/* path to script */ $1,
/* actions */ a,
/* transformations */ t,
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
/* file name */ std::string(*@1.end.filename),
/* line number */ @1.end.line
));

Expand Down Expand Up @@ -1240,7 +1240,7 @@ expression:
| CONFIG_DIR_SEC_MARKER
{
driver.addSecMarker(modsecurity::utils::string::removeBracketsIfNeeded($1),
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
/* file name */ std::string(*@1.end.filename),
/* line number */ @1.end.line
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/rule_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class RuleScript : public RuleWithActions {
RuleScript(const std::string &name,
std::vector<Action *> *actions,
Transformations *t,
std::unique_ptr<std::string> fileName,
const std::string &fileName,
int lineNumber)
: RuleWithActions(actions, t, std::move(fileName), lineNumber),
: RuleWithActions(actions, t, fileName, lineNumber),
m_name(name),
m_lua() { }

Expand Down
4 changes: 2 additions & 2 deletions src/rule_with_actions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ using actions::transformations::Transformation;
RuleWithActions::RuleWithActions(
Actions *actions,
Transformations *transformations,
std::unique_ptr<std::string> fileName,
const std::string &fileName,
int lineNumber)
: Rule(std::move(fileName), lineNumber),
: Rule(fileName, lineNumber),
m_rev(""),
m_ver(""),
m_accuracy(0),
Expand Down
2 changes: 1 addition & 1 deletion src/rule_with_operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ RuleWithOperator::RuleWithOperator(Operator *op,
variables::Variables *_variables,
std::vector<Action *> *actions,
Transformations *transformations,
std::unique_ptr<std::string> fileName,
const std::string &fileName,
int lineNumber)
: RuleWithActions(actions, transformations, std::move(fileName), lineNumber),
m_variables(_variables),
Expand Down
2 changes: 1 addition & 1 deletion src/variables/variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class VariableMonkeyResolution {

static std::string stringMatchResolve(Transaction *t,
const std::string &variable) {
std::unique_ptr<std::string> vv = nullptr;
std::unique_ptr<std::string> vv;
size_t collection = variable.find(".");
if (collection == std::string::npos) {
collection = variable.find(":");
Expand Down

0 comments on commit b95abc9

Please sign in to comment.