@@ -1069,15 +1069,15 @@ expression:
1069
1069
audit_log
1070
1070
| DIRECTIVE variables op actions
1071
1071
{
1072
- std::vector<actions::Action *> *a = new std::vector<actions::Action * >();
1072
+ std::vector<std::shared_ptr< actions::Action>> *a = new std::vector<std::shared_ptr< actions::Action> >();
1073
1073
std::vector<std::shared_ptr<actions::transformations::Transformation> > *t = new std::vector<std::shared_ptr<actions::transformations::Transformation> >();
1074
1074
for (auto &i : *$4 .get ()) {
1075
1075
if (dynamic_cast <actions::transformations::Transformation *>(i.get ())) {
1076
1076
std::shared_ptr<actions::Action> at = std::move (i);
1077
1077
std::shared_ptr<actions::transformations::Transformation> t2 = std::dynamic_pointer_cast<actions::transformations::Transformation>(std::move (at));
1078
1078
t->push_back (std::move (t2));
1079
1079
} else {
1080
- a->push_back (i. release ( ));
1080
+ a->push_back (std::move (i ));
1081
1081
}
1082
1082
}
1083
1083
variables::Variables *v = new variables::Variables ();
@@ -1094,7 +1094,7 @@ expression:
1094
1094
/* file name */ std::unique_ptr<std::string>(new std::string (*@1 .end .filename )),
1095
1095
/* line number */ @1 .end .line
1096
1096
));
1097
-
1097
+ // TODO: filename should be a shared_ptr.
1098
1098
if (driver.addSecRule (std::move (rule)) == false ) {
1099
1099
YYERROR;
1100
1100
}
@@ -1120,15 +1120,15 @@ expression:
1120
1120
}
1121
1121
| CONFIG_DIR_SEC_ACTION actions
1122
1122
{
1123
- std::vector<actions::Action *> *a = new std::vector<actions::Action * >();
1123
+ std::vector<std::shared_ptr< actions::Action>> *a = new std::vector<std::shared_ptr< actions::Action> >();
1124
1124
std::vector<std::shared_ptr<actions::transformations::Transformation> > *t = new std::vector<std::shared_ptr<actions::transformations::Transformation> >();
1125
1125
for (auto &i : *$2 .get ()) {
1126
1126
if (dynamic_cast <actions::transformations::Transformation *>(i.get ())) {
1127
1127
std::shared_ptr<actions::Action> at = std::move (i);
1128
1128
std::shared_ptr<actions::transformations::Transformation> t2 = std::dynamic_pointer_cast<actions::transformations::Transformation>(std::move (at));
1129
1129
t->push_back (std::move (t2));
1130
1130
} else {
1131
- a->push_back (i. release ( ));
1131
+ a->push_back (std::move (i ));
1132
1132
}
1133
1133
}
1134
1134
std::unique_ptr<RuleUnconditional> rule (new RuleUnconditional (
@@ -1142,15 +1142,15 @@ expression:
1142
1142
| DIRECTIVE_SECRULESCRIPT actions
1143
1143
{
1144
1144
std::string err;
1145
- std::vector<actions::Action *> *a = new std::vector<actions::Action * >();
1145
+ std::vector<std::shared_ptr< actions::Action>> *a = new std::vector<std::shared_ptr< actions::Action> >();
1146
1146
std::vector<std::shared_ptr<actions::transformations::Transformation> > *t = new std::vector<std::shared_ptr<actions::transformations::Transformation> >();
1147
1147
for (auto &i : *$2 .get ()) {
1148
1148
if (dynamic_cast <actions::transformations::Transformation *>(i.get ())) {
1149
1149
std::shared_ptr<actions::Action> at = std::move (i);
1150
1150
std::shared_ptr<actions::transformations::Transformation> t2 = std::dynamic_pointer_cast<actions::transformations::Transformation>(std::move (at));
1151
1151
t->push_back (std::move (t2));
1152
1152
} else {
1153
- a->push_back (i. release ( ));
1153
+ a->push_back (std::move (i ));
1154
1154
}
1155
1155
}
1156
1156
std::unique_ptr<RuleScript> r (new RuleScript (
@@ -1172,25 +1172,25 @@ expression:
1172
1172
| CONFIG_DIR_SEC_DEFAULT_ACTION actions
1173
1173
{
1174
1174
bool hasDisruptive = false ;
1175
- std::vector<actions::Action *> *actions = new std::vector<actions::Action * >();
1175
+ std::vector<std::shared_ptr< actions::Action>> *actions = new std::vector<std::shared_ptr< actions::Action> >();
1176
1176
for (auto &i : *$2 .get ()) {
1177
- actions->push_back (i. release ( ));
1177
+ actions->push_back (std::move (i ));
1178
1178
}
1179
- std::vector<actions::Action * > checkedActions;
1179
+ std::vector<std::shared_ptr< actions::Action> > checkedActions;
1180
1180
int definedPhase = -1 ;
1181
1181
int secRuleDefinedPhase = -1 ;
1182
- for (actions::Action * a : *actions) {
1183
- actions::Phase *phase = dynamic_cast <actions::Phase *>(a);
1184
- if (dynamic_cast <actions::disruptive::ActionDisruptive *>(a) != NULL
1185
- && dynamic_cast <actions::Block *>(a) == NULL ) {
1182
+ for (auto & a : *actions) {
1183
+ actions::Phase *phase = dynamic_cast <actions::Phase *>(a. get () );
1184
+ if (dynamic_cast <actions::disruptive::ActionDisruptive *>(a. get () ) != NULL
1185
+ && dynamic_cast <actions::Block *>(a. get () ) == NULL ) {
1186
1186
hasDisruptive = true ;
1187
1187
}
1188
1188
if (phase != NULL ) {
1189
1189
definedPhase = phase->getPhase ();
1190
1190
secRuleDefinedPhase = phase->getSecRulePhase ();
1191
1191
delete phase;
1192
- } else if (dynamic_cast <actions::ActionAllowedAsSecDefaultAction *>(a)
1193
- && !dynamic_cast <actions::transformations::None *>(a)) {
1192
+ } else if (dynamic_cast <actions::ActionAllowedAsSecDefaultAction *>(a. get () )
1193
+ && !dynamic_cast <actions::transformations::None *>(a. get () )) {
1194
1194
checkedActions.push_back (a);
1195
1195
} else {
1196
1196
driver.error (@0 , " The action '" + *a->getName () + " ' is not suitable to be part of the SecDefaultActions" );
@@ -1200,12 +1200,10 @@ expression:
1200
1200
if (definedPhase == -1 ) {
1201
1201
definedPhase = modsecurity::Phases::RequestHeadersPhase;
1202
1202
}
1203
-
1204
1203
if (hasDisruptive == false ) {
1205
1204
driver.error (@0 , " SecDefaultAction must specify a disruptive action." );
1206
1205
YYERROR;
1207
1206
}
1208
-
1209
1207
if (!driver.m_rulesSetPhases [definedPhase]->m_defaultActions .empty ()) {
1210
1208
std::stringstream ss;
1211
1209
ss << " SecDefaultActions can only be placed once per phase and configuration context. Phase " ;
@@ -1214,18 +1212,15 @@ expression:
1214
1212
driver.error (@0 , ss.str ());
1215
1213
YYERROR;
1216
1214
}
1217
-
1218
- for (actions::Action *a : checkedActions) {
1219
- if (dynamic_cast <actions::transformations::Transformation *>(a)) {
1215
+ for (auto &a : checkedActions) {
1216
+ if (dynamic_cast <actions::transformations::Transformation *>(a.get ())) {
1220
1217
driver.m_rulesSetPhases [definedPhase]->m_defaultTransformations .push_back (
1221
- std::shared_ptr<actions::transformations::Transformation>(
1222
- dynamic_cast <actions::transformations::Transformation *>(a)));
1218
+ std::dynamic_pointer_cast<actions::transformations::Transformation>(a));
1223
1219
} else {
1224
- driver.m_rulesSetPhases [definedPhase]->m_defaultActions .push_back (std::unique_ptr<Action>(a) );
1220
+ driver.m_rulesSetPhases [definedPhase]->m_defaultActions .push_back (a );
1225
1221
}
1226
1222
}
1227
-
1228
- delete actions;
1223
+ // delete actions;
1229
1224
}
1230
1225
| CONFIG_DIR_SEC_MARKER
1231
1226
{
0 commit comments