mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 13:26:01 +03:00
Simplify initialization of fileName member of Rule instances
This commit is contained in:
parent
2ad87f640f
commit
2c613fb77c
@ -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) {
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
~RuleWithActions() override;
|
||||
|
@ -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);
|
||||
|
||||
~RuleWithOperator() override;
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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() { }
|
||||
|
||||
|
@ -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),
|
||||
|
@ -55,9 +55,9 @@ 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),
|
||||
: RuleWithActions(actions, transformations, fileName, lineNumber),
|
||||
m_variables(_variables),
|
||||
m_operator(op) { /* */ }
|
||||
|
||||
|
@ -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(":");
|
||||
|
Loading…
x
Reference in New Issue
Block a user