Skip to content

fix memory patch, should close #2710 #2728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions headers/modsecurity/rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class Rule {
return *this;
}

virtual ~Rule() {}

virtual bool evaluate(Transaction *transaction) = 0;

virtual bool evaluate(Transaction *transaction,
Expand Down
4 changes: 2 additions & 2 deletions src/parser/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ int Driver::parse(const std::string &f, const std::string &ref) {
m_lastRule = nullptr;
loc.push_back(new yy::location());
if (ref.empty()) {
loc.back()->begin.filename = loc.back()->end.filename = new std::string("<<reference missing or not informed>>");
loc.back()->begin.filename = loc.back()->end.filename = std::make_shared<const std::string>("<<reference missing or not informed>>");
} else {
loc.back()->begin.filename = loc.back()->end.filename = new std::string(ref);
loc.back()->begin.filename = loc.back()->end.filename = std::make_shared<const std::string>(ref);
}

if (f.empty()) {
Expand Down
4 changes: 2 additions & 2 deletions src/parser/location.hh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace yy {
counter_type l = 1,
counter_type c = 1)
{
filename = fn;
filename = std::shared_ptr<filename_type>(fn);
line = l;
column = c;
}
Expand All @@ -105,7 +105,7 @@ namespace yy {
/** \} */

/// File name to which this position refers.
filename_type* filename;
std::shared_ptr<filename_type> filename;
/// Current line number.
counter_type line;
/// Current column number.
Expand Down
14 changes: 7 additions & 7 deletions src/parser/seclang-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ namespace yy {
#line 320 "seclang-parser.yy"
{
// Initialize the initial location.
yyla.location.begin.filename = yyla.location.end.filename = new std::string(driver.file);
yyla.location.begin.filename = yyla.location.end.filename = std::make_shared<const std::string>(driver.file);
}

#line 1328 "seclang-parser.cc"
Expand Down Expand Up @@ -2287,7 +2287,7 @@ namespace yy {
#line 1078 "seclang-parser.yy"
{
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
for (auto &i : *yystack_[0].value.as < std::unique_ptr<std::vector<std::unique_ptr<actions::Action> > > > ().get()) {
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
Expand All @@ -2305,7 +2305,7 @@ namespace yy {
/* op */ op,
/* variables */ v,
/* actions */ a,
/* transformations */ t,
/* transformations */ t.get(),
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[3].location.end.filename)),
/* line number */ yystack_[3].location.end.line
));
Expand Down Expand Up @@ -2344,7 +2344,7 @@ namespace yy {
#line 1127 "seclang-parser.yy"
{
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
for (auto &i : *yystack_[0].value.as < std::unique_ptr<std::vector<std::unique_ptr<actions::Action> > > > ().get()) {
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
Expand All @@ -2354,7 +2354,7 @@ namespace yy {
}
std::unique_ptr<RuleUnconditional> rule(new RuleUnconditional(
/* actions */ a,
/* transformations */ t,
/* transformations */ t.get(),
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[1].location.end.filename)),
/* line number */ yystack_[1].location.end.line
));
Expand All @@ -2368,7 +2368,7 @@ namespace yy {
{
std::string err;
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
for (auto &i : *yystack_[0].value.as < std::unique_ptr<std::vector<std::unique_ptr<actions::Action> > > > ().get()) {
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
Expand All @@ -2379,7 +2379,7 @@ namespace yy {
std::unique_ptr<RuleScript> r(new RuleScript(
/* path to script */ yystack_[1].value.as < std::string > (),
/* actions */ a,
/* transformations */ t,
/* transformations */ t.get(),
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[1].location.end.filename)),
/* line number */ yystack_[1].location.end.line
));
Expand Down
14 changes: 7 additions & 7 deletions src/parser/seclang-parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ using namespace modsecurity::operators;
%initial-action
{
// Initialize the initial location.
@$.begin.filename = @$.end.filename = new std::string(driver.file);
@$.begin.filename = @$.end.filename = std::make_shared<const std::string>(driver.file);
};
%define parse.trace
%define parse.error verbose
Expand Down Expand Up @@ -1077,7 +1077,7 @@ expression:
| DIRECTIVE variables op actions
{
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
for (auto &i : *$4.get()) {
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
Expand All @@ -1095,7 +1095,7 @@ expression:
/* op */ op,
/* variables */ v,
/* actions */ a,
/* transformations */ t,
/* transformations */ t.get(),
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
/* line number */ @1.end.line
));
Expand Down Expand Up @@ -1126,7 +1126,7 @@ expression:
| CONFIG_DIR_SEC_ACTION actions
{
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
for (auto &i : *$2.get()) {
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
Expand All @@ -1136,7 +1136,7 @@ expression:
}
std::unique_ptr<RuleUnconditional> rule(new RuleUnconditional(
/* actions */ a,
/* transformations */ t,
/* transformations */ t.get(),
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
/* line number */ @1.end.line
));
Expand All @@ -1146,7 +1146,7 @@ expression:
{
std::string err;
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
auto t = std::make_shared<std::vector<actions::transformations::Transformation *>>();
for (auto &i : *$2.get()) {
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
Expand All @@ -1157,7 +1157,7 @@ expression:
std::unique_ptr<RuleScript> r(new RuleScript(
/* path to script */ $1,
/* actions */ a,
/* transformations */ t,
/* transformations */ t.get(),
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
/* line number */ @1.end.line
));
Expand Down
6 changes: 3 additions & 3 deletions src/parser/seclang-scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8544,7 +8544,7 @@ YY_RULE_SETUP
std::string err;
std::string f = modsecurity::utils::find_resource(s, *driver.loc.back()->end.filename, &err);
driver.loc.push_back(new yy::location());
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(f);
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(f);
yyin = fopen(f.c_str(), "r" );
if (!yyin) {
BEGIN(INITIAL);
Expand Down Expand Up @@ -8575,7 +8575,7 @@ YY_RULE_SETUP
for (auto& s: files) {
std::string f = modsecurity::utils::find_resource(s, *driver.loc.back()->end.filename, &err);
driver.loc.push_back(new yy::location());
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(f);
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(f);

yyin = fopen(f.c_str(), "r" );
if (!yyin) {
Expand Down Expand Up @@ -8608,7 +8608,7 @@ YY_RULE_SETUP
c.setKey(key);

driver.loc.push_back(new yy::location());
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(url);
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(url);
YY_BUFFER_STATE temp = YY_CURRENT_BUFFER;
yypush_buffer_state(temp);

Expand Down
6 changes: 3 additions & 3 deletions src/parser/seclang-scanner.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ EQUALS_MINUS (?i:=\-)
std::string err;
std::string f = modsecurity::utils::find_resource(s, *driver.loc.back()->end.filename, &err);
driver.loc.push_back(new yy::location());
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(f);
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(f);
yyin = fopen(f.c_str(), "r" );
if (!yyin) {
BEGIN(INITIAL);
Expand Down Expand Up @@ -1285,7 +1285,7 @@ EQUALS_MINUS (?i:=\-)
for (auto& s: files) {
std::string f = modsecurity::utils::find_resource(s, *driver.loc.back()->end.filename, &err);
driver.loc.push_back(new yy::location());
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(f);
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(f);

yyin = fopen(f.c_str(), "r" );
if (!yyin) {
Expand Down Expand Up @@ -1314,7 +1314,7 @@ EQUALS_MINUS (?i:=\-)
c.setKey(key);

driver.loc.push_back(new yy::location());
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = new std::string(url);
driver.loc.back()->begin.filename = driver.loc.back()->end.filename = std::make_shared<const std::string>(url);
YY_BUFFER_STATE temp = YY_CURRENT_BUFFER;
yypush_buffer_state(temp);

Expand Down