Skip to content
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

fix: Sonarcloud memleak fixes #3114

Open
wants to merge 6 commits into
base: v3/master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions test/regression/regression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,9 @@ int main(int argc, char **argv) {
ModSecurityTest<RegressionTest> test;

std::string ver(MODSECURITY_VERSION);
std::string envvar("MODSECURITY=ModSecurity " + ver + " regression tests");
std::string envvar("ModSecurity " + ver + " regression tests");

putenv(strdup(envvar.c_str()));
setenv("MODSECURITY", envvar.c_str(), 1);
#ifndef NO_LOGS
int test_number = 0;
#endif
Expand Down Expand Up @@ -606,5 +606,6 @@ int main(int argc, char **argv) {
}

#endif

return 0;
}
44 changes: 13 additions & 31 deletions tools/rules-check/rules-check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ void print_help(const char *name) {


int main(int argc, char **argv) {
modsecurity::RulesSet *rules;
auto rules = std::make_unique<modsecurity::RulesSet>();
char **args = argv;
rules = new modsecurity::RulesSet();
int ret = 0;

args++;
Expand All @@ -46,41 +45,26 @@ int main(int argc, char **argv) {

while (*args != NULL) {
struct stat buffer;
std::string argFull("");
const char *arg = *args;
std::string arg = *args;
std::string err;
int r;

if (argFull.empty() == false) {
if (arg[strlen(arg)-1] == '\"') {
argFull.append(arg, strlen(arg)-1);
goto next;
} else {
argFull.append(arg);
goto next;
}
}

if (arg[0] == '\"' && argFull.empty() == true) {
if (arg[strlen(arg)-1] == '\"') {
argFull.append(arg+1, strlen(arg) - 2);
} else {
argFull.append(arg+1);
goto next;
}
}
// strip arg from leading and trailing '"' chars
arg.erase(arg.find_last_not_of('\"')+1);
arg.erase(0, arg.find_first_not_of('\"'));

if (argFull.empty() == false) {
arg = strdup(argFull.c_str());
argFull.clear();
if (arg.empty() == true) {
args++;
continue;
}

std::cout << " : " << arg << " -- ";
if (stat(arg, &buffer) == 0) {
r = rules->loadFromUri(arg);
if (stat(arg.c_str(), &buffer) == 0) {
r = rules->loadFromUri(arg.c_str());
} else {
r = rules->load(arg);
r = rules->load(arg.c_str());
}

if (r < 0) {
err.assign(rules->m_parserError.str());
rules->m_parserError.str("");
Expand All @@ -91,12 +75,10 @@ int main(int argc, char **argv) {
if (err.empty() == false) {
std::cerr << " " << err << std::endl;
}
next:

args++;
}

delete rules;

if (ret < 0) {
std::cout << "Test failed." << std::endl;
} else {
Expand Down
Loading