Skip to content

Commit 67f32a4

Browse files
committed
Fix cppcheck 2.18.0 warnings
1 parent 0ac551b commit 67f32a4

File tree

6 files changed

+23
-20
lines changed

6 files changed

+23
-20
lines changed

src/operators/fuzzy_hash.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bool FuzzyHash::init(const std::string &param2, std::string *error) {
2727
#ifdef WITH_SSDEEP
2828
std::string digit;
2929
std::string file;
30-
std::istream *iss;
30+
std::ifstream *iss;
3131
std::shared_ptr<fuzzy_hash_chunk> chunk, t;
3232
std::string err;
3333

@@ -48,7 +48,7 @@ bool FuzzyHash::init(const std::string &param2, std::string *error) {
4848
std::string resource = utils::find_resource(file, param2, &err);
4949
iss = new std::ifstream(resource, std::ios::in);
5050

51-
if (((std::ifstream *)iss)->is_open() == false) {
51+
if ((iss)->is_open() == false) {
5252
error->assign("Failed to open file: " + m_param + ". " + err);
5353
delete iss;
5454
return false;

src/operators/inspect_file.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ namespace modsecurity {
3131
namespace operators {
3232

3333
bool InspectFile::init(const std::string &param2, std::string *error) {
34-
std::istream *iss;
34+
std::ifstream *iss;
3535
std::string err;
3636
std::string err_lua;
3737

3838
m_file = utils::find_resource(m_param, param2, &err);
3939
iss = new std::ifstream(m_file, std::ios::in);
4040

41-
if (((std::ifstream *)iss)->is_open() == false) {
41+
if ((iss)->is_open() == false) {
4242
error->assign("Failed to open file: " + m_param + ". " + err);
4343
delete iss;
4444
return false;

src/operators/pm_from_file.cc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bool PmFromFile::init(const std::string &config, std::string *error) {
5151
for (const auto& token : tokens) {
5252
if (! token.empty()) {
5353

54-
std::istream *iss;
54+
std::unique_ptr<std::istream> iss;
5555

5656
if (token.compare(0, 8, "https://") == 0) {
5757
Utils::HttpsClient client;
@@ -60,26 +60,22 @@ bool PmFromFile::init(const std::string &config, std::string *error) {
6060
error->assign(client.error);
6161
return false;
6262
}
63-
iss = new std::stringstream(client.content);
63+
iss = std::make_unique<std::stringstream>(client.content);
6464
} else {
6565
std::string err;
6666
std::string resource = utils::find_resource(token, config, &err);
67-
iss = new std::ifstream(resource, std::ios::in);
68-
69-
if (((std::ifstream *)iss)->is_open() == false) {
67+
auto file = std::make_unique<std::ifstream>(resource, std::ios::in);
68+
if (file->is_open() == false) {
7069
error->assign("Failed to open file: '" + token + "'. " + err);
71-
delete iss;
7270
return false;
7371
}
72+
iss = std::move(file);
7473
}
75-
7674
for (std::string line; std::getline(*iss, line); ) {
7775
if (isComment(line) == false) {
7876
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
7977
}
8078
}
81-
82-
delete iss;
8379
}
8480
}
8581

src/operators/rbl.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,15 @@ bool Rbl::evaluate(Transaction *t, RuleWithActions *rule,
227227
}
228228

229229
struct sockaddr *addr = info->ai_addr;
230-
struct sockaddr_in *sin = (struct sockaddr_in *) addr;
231-
furtherInfo(sin, ipStr, t, m_provider);
230+
if (addr->sa_family == AF_INET) { // only IPv4 address is allowed
231+
struct sockaddr_in *sin = reinterpret_cast<struct sockaddr_in *>(addr);
232+
furtherInfo(sin, ipStr, t, m_provider);
233+
}
234+
else {
235+
ms_dbg_a(t, 7, "Unsupported address family: " + std::to_string(addr->sa_family));
236+
freeaddrinfo(info);
237+
return false;
238+
}
232239

233240
freeaddrinfo(info);
234241
if (rule && t && rule->hasCaptureAction()) {

src/operators/validate_dtd.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool ValidateDTD::init(const std::string &file, std::string *error) {
4545

4646
bool ValidateDTD::evaluate(Transaction *transaction, const std::string &str) {
4747

48-
XmlDtdPtrManager dtd(xmlParseDTD(NULL, (const xmlChar *)m_resource.c_str()));
48+
XmlDtdPtrManager dtd(xmlParseDTD(NULL, reinterpret_cast<const xmlChar *>(m_resource.c_str())));
4949
if (dtd.get() == NULL) {
5050
std::string err = std::string("XML: Failed to load DTD: ") \
5151
+ m_resource;

src/variables/xml.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void XML::evaluate(Transaction *t,
7979
}
8080

8181
/* Process the XPath expression. */
82-
xpathExpr = (const xmlChar*)param.c_str();
82+
xpathExpr = reinterpret_cast<const xmlChar*>(param.c_str());
8383
xpathCtx = xmlXPathNewContext(t->m_xml->m_data.doc);
8484
if (xpathCtx == NULL) {
8585
ms_dbg_a(t, 1, "XML: Unable to create new XPath context. : ");
@@ -91,9 +91,9 @@ void XML::evaluate(Transaction *t,
9191
} else {
9292
std::vector<actions::Action *> acts = rule->getActionsByName("xmlns", t);
9393
for (auto &x : acts) {
94-
actions::XmlNS *z = (actions::XmlNS *)x;
95-
if (xmlXPathRegisterNs(xpathCtx, (const xmlChar*)z->m_scope.c_str(),
96-
(const xmlChar*)z->m_href.c_str()) != 0) {
94+
actions::XmlNS *z = reinterpret_cast<actions::XmlNS *>(x);
95+
if (xmlXPathRegisterNs(xpathCtx, reinterpret_cast<const xmlChar*>(z->m_scope.c_str()),
96+
reinterpret_cast<const xmlChar*>(z->m_href.c_str())) != 0) {
9797
ms_dbg_a(t, 1, "Failed to register XML namespace href \"" + \
9898
z->m_href + "\" prefix \"" + z->m_scope + "\".");
9999
return;

0 commit comments

Comments
 (0)