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

@@ -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));
}

View File

@@ -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();

View File

@@ -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
));
@@ -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) {
@@ -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));
@@ -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
));
@@ -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
);
}

View File

@@ -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
));
@@ -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) {
@@ -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));
@@ -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
));
@@ -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
);
}