Simplify initialization of fileName member of Rule instances

This commit is contained in:
Eduardo Arias 2024-05-06 01:39:55 -03:00
parent 2ad87f640f
commit 2c613fb77c
12 changed files with 26 additions and 27 deletions

View File

@ -64,8 +64,8 @@ using MatchActions = std::vector<actions::Action *>;
class Rule { class Rule {
public: public:
Rule(std::unique_ptr<std::string> fileName, int lineNumber) Rule(const std::string &fileName, int lineNumber)
: m_fileName(*fileName), : m_fileName(fileName),
m_lineNumber(lineNumber), m_lineNumber(lineNumber),
m_phase(modsecurity::Phases::RequestHeadersPhase) { m_phase(modsecurity::Phases::RequestHeadersPhase) {
} }

View File

@ -33,9 +33,9 @@ class RuleMarker : public Rule {
public: public:
RuleMarker( RuleMarker(
const std::string &name, const std::string &name,
std::unique_ptr<std::string> fileName, const std::string &fileName,
int lineNumber) int lineNumber)
: Rule(std::move(fileName), lineNumber), : Rule(fileName, lineNumber),
m_name(name) { } m_name(name) { }
RuleMarker(const RuleMarker &r) = delete; RuleMarker(const RuleMarker &r) = delete;

View File

@ -40,7 +40,7 @@ class RuleWithActions : public Rule {
RuleWithActions( RuleWithActions(
Actions *a, Actions *a,
Transformations *t, Transformations *t,
std::unique_ptr<std::string> fileName, const std::string &fileName,
int lineNumber); int lineNumber);
~RuleWithActions() override; ~RuleWithActions() override;

View File

@ -42,7 +42,7 @@ class RuleWithOperator : public RuleWithActions {
variables::Variables *variables, variables::Variables *variables,
std::vector<actions::Action *> *actions, std::vector<actions::Action *> *actions,
Transformations *transformations, Transformations *transformations,
std::unique_ptr<std::string> fileName, const std::string &fileName,
int lineNumber); int lineNumber);
~RuleWithOperator() override; ~RuleWithOperator() override;

View File

@ -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. // FIXME: we might move this to the parser.
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) { 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); auto rule = std::make_unique<RuleMarker>(marker, fileName, lineNumber);
std::unique_ptr<RuleMarker> rule(r);
rule->setPhase(i); rule->setPhase(i);
m_rulesSetPhases.insert(std::move(rule)); m_rulesSetPhases.insert(std::move(rule));
} }

View File

@ -60,7 +60,7 @@ class Driver : public RulesSetProperties {
int addSecRule(std::unique_ptr<RuleWithActions> rule); int addSecRule(std::unique_ptr<RuleWithActions> rule);
int addSecAction(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); int addSecRuleScript(std::unique_ptr<RuleScript> rule);
bool scan_begin(); bool scan_begin();

View File

@ -2313,7 +2313,7 @@ namespace yy {
/* variables */ v, /* variables */ v,
/* actions */ a, /* actions */ a,
/* transformations */ t, /* 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 /* line number */ yystack_[3].location.end.line
)); ));
@ -2337,7 +2337,7 @@ namespace yy {
/* variables */ v, /* variables */ v,
/* actions */ NULL, /* actions */ NULL,
/* transformations */ 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 /* line number */ yystack_[2].location.end.line
)); ));
if (driver.addSecRule(std::move(rule)) == false) { if (driver.addSecRule(std::move(rule)) == false) {
@ -2363,7 +2363,7 @@ namespace yy {
std::unique_ptr<RuleUnconditional> rule(new RuleUnconditional( std::unique_ptr<RuleUnconditional> rule(new RuleUnconditional(
/* actions */ a, /* actions */ a,
/* transformations */ t, /* 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 /* line number */ yystack_[1].location.end.line
)); ));
driver.addSecAction(std::move(rule)); driver.addSecAction(std::move(rule));
@ -2389,7 +2389,7 @@ namespace yy {
/* path to script */ yystack_[1].value.as < std::string > (), /* path to script */ yystack_[1].value.as < std::string > (),
/* actions */ a, /* actions */ a,
/* transformations */ t, /* 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 /* line number */ yystack_[1].location.end.line
)); ));
@ -2469,7 +2469,7 @@ namespace yy {
#line 1241 "seclang-parser.yy" #line 1241 "seclang-parser.yy"
{ {
driver.addSecMarker(modsecurity::utils::string::removeBracketsIfNeeded(yystack_[0].value.as < std::string > ()), 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 /* line number */ yystack_[0].location.end.line
); );
} }

View File

@ -1104,7 +1104,7 @@ expression:
/* variables */ v, /* variables */ v,
/* actions */ a, /* actions */ a,
/* transformations */ t, /* 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 /* line number */ @1.end.line
)); ));
@ -1124,7 +1124,7 @@ expression:
/* variables */ v, /* variables */ v,
/* actions */ NULL, /* actions */ NULL,
/* transformations */ 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 /* line number */ @1.end.line
)); ));
if (driver.addSecRule(std::move(rule)) == false) { if (driver.addSecRule(std::move(rule)) == false) {
@ -1146,7 +1146,7 @@ expression:
std::unique_ptr<RuleUnconditional> rule(new RuleUnconditional( std::unique_ptr<RuleUnconditional> rule(new RuleUnconditional(
/* actions */ a, /* actions */ a,
/* transformations */ t, /* 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 /* line number */ @1.end.line
)); ));
driver.addSecAction(std::move(rule)); driver.addSecAction(std::move(rule));
@ -1168,7 +1168,7 @@ expression:
/* path to script */ $1, /* path to script */ $1,
/* actions */ a, /* actions */ a,
/* transformations */ t, /* 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 /* line number */ @1.end.line
)); ));
@ -1240,7 +1240,7 @@ expression:
| CONFIG_DIR_SEC_MARKER | CONFIG_DIR_SEC_MARKER
{ {
driver.addSecMarker(modsecurity::utils::string::removeBracketsIfNeeded($1), 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 /* line number */ @1.end.line
); );
} }

View File

@ -47,9 +47,9 @@ class RuleScript : public RuleWithActions {
RuleScript(const std::string &name, RuleScript(const std::string &name,
std::vector<Action *> *actions, std::vector<Action *> *actions,
Transformations *t, Transformations *t,
std::unique_ptr<std::string> fileName, const std::string &fileName,
int lineNumber) int lineNumber)
: RuleWithActions(actions, t, std::move(fileName), lineNumber), : RuleWithActions(actions, t, fileName, lineNumber),
m_name(name), m_name(name),
m_lua() { } m_lua() { }

View File

@ -59,9 +59,9 @@ using actions::transformations::Transformation;
RuleWithActions::RuleWithActions( RuleWithActions::RuleWithActions(
Actions *actions, Actions *actions,
Transformations *transformations, Transformations *transformations,
std::unique_ptr<std::string> fileName, const std::string &fileName,
int lineNumber) int lineNumber)
: Rule(std::move(fileName), lineNumber), : Rule(fileName, lineNumber),
m_rev(""), m_rev(""),
m_ver(""), m_ver(""),
m_accuracy(0), m_accuracy(0),

View File

@ -55,9 +55,9 @@ RuleWithOperator::RuleWithOperator(Operator *op,
variables::Variables *_variables, variables::Variables *_variables,
std::vector<Action *> *actions, std::vector<Action *> *actions,
Transformations *transformations, Transformations *transformations,
std::unique_ptr<std::string> fileName, const std::string &fileName,
int lineNumber) int lineNumber)
: RuleWithActions(actions, transformations, std::move(fileName), lineNumber), : RuleWithActions(actions, transformations, fileName, lineNumber),
m_variables(_variables), m_variables(_variables),
m_operator(op) { /* */ } m_operator(op) { /* */ }

View File

@ -379,7 +379,7 @@ class VariableMonkeyResolution {
static std::string stringMatchResolve(Transaction *t, static std::string stringMatchResolve(Transaction *t,
const std::string &variable) { const std::string &variable) {
std::unique_ptr<std::string> vv = nullptr; std::unique_ptr<std::string> vv;
size_t collection = variable.find("."); size_t collection = variable.find(".");
if (collection == std::string::npos) { if (collection == std::string::npos) {
collection = variable.find(":"); collection = variable.find(":");