mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 13:26:01 +03:00
Fix cppcheck 2.18.0 warnings
This commit is contained in:
parent
0ac551b070
commit
67f32a4e63
@ -27,7 +27,7 @@ bool FuzzyHash::init(const std::string ¶m2, std::string *error) {
|
||||
#ifdef WITH_SSDEEP
|
||||
std::string digit;
|
||||
std::string file;
|
||||
std::istream *iss;
|
||||
std::ifstream *iss;
|
||||
std::shared_ptr<fuzzy_hash_chunk> chunk, t;
|
||||
std::string err;
|
||||
|
||||
@ -48,7 +48,7 @@ bool FuzzyHash::init(const std::string ¶m2, std::string *error) {
|
||||
std::string resource = utils::find_resource(file, param2, &err);
|
||||
iss = new std::ifstream(resource, std::ios::in);
|
||||
|
||||
if (((std::ifstream *)iss)->is_open() == false) {
|
||||
if ((iss)->is_open() == false) {
|
||||
error->assign("Failed to open file: " + m_param + ". " + err);
|
||||
delete iss;
|
||||
return false;
|
||||
|
@ -31,14 +31,14 @@ namespace modsecurity {
|
||||
namespace operators {
|
||||
|
||||
bool InspectFile::init(const std::string ¶m2, std::string *error) {
|
||||
std::istream *iss;
|
||||
std::ifstream *iss;
|
||||
std::string err;
|
||||
std::string err_lua;
|
||||
|
||||
m_file = utils::find_resource(m_param, param2, &err);
|
||||
iss = new std::ifstream(m_file, std::ios::in);
|
||||
|
||||
if (((std::ifstream *)iss)->is_open() == false) {
|
||||
if ((iss)->is_open() == false) {
|
||||
error->assign("Failed to open file: " + m_param + ". " + err);
|
||||
delete iss;
|
||||
return false;
|
||||
|
@ -51,7 +51,7 @@ bool PmFromFile::init(const std::string &config, std::string *error) {
|
||||
for (const auto& token : tokens) {
|
||||
if (! token.empty()) {
|
||||
|
||||
std::istream *iss;
|
||||
std::unique_ptr<std::istream> iss;
|
||||
|
||||
if (token.compare(0, 8, "https://") == 0) {
|
||||
Utils::HttpsClient client;
|
||||
@ -60,26 +60,22 @@ bool PmFromFile::init(const std::string &config, std::string *error) {
|
||||
error->assign(client.error);
|
||||
return false;
|
||||
}
|
||||
iss = new std::stringstream(client.content);
|
||||
iss = std::make_unique<std::stringstream>(client.content);
|
||||
} else {
|
||||
std::string err;
|
||||
std::string resource = utils::find_resource(token, config, &err);
|
||||
iss = new std::ifstream(resource, std::ios::in);
|
||||
|
||||
if (((std::ifstream *)iss)->is_open() == false) {
|
||||
auto file = std::make_unique<std::ifstream>(resource, std::ios::in);
|
||||
if (file->is_open() == false) {
|
||||
error->assign("Failed to open file: '" + token + "'. " + err);
|
||||
delete iss;
|
||||
return false;
|
||||
}
|
||||
iss = std::move(file);
|
||||
}
|
||||
|
||||
for (std::string line; std::getline(*iss, line); ) {
|
||||
if (isComment(line) == false) {
|
||||
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
|
||||
}
|
||||
}
|
||||
|
||||
delete iss;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -227,8 +227,15 @@ bool Rbl::evaluate(Transaction *t, RuleWithActions *rule,
|
||||
}
|
||||
|
||||
struct sockaddr *addr = info->ai_addr;
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *) addr;
|
||||
furtherInfo(sin, ipStr, t, m_provider);
|
||||
if (addr->sa_family == AF_INET) { // only IPv4 address is allowed
|
||||
struct sockaddr_in *sin = reinterpret_cast<struct sockaddr_in *>(addr);
|
||||
furtherInfo(sin, ipStr, t, m_provider);
|
||||
}
|
||||
else {
|
||||
ms_dbg_a(t, 7, "Unsupported address family: " + std::to_string(addr->sa_family));
|
||||
freeaddrinfo(info);
|
||||
return false;
|
||||
}
|
||||
|
||||
freeaddrinfo(info);
|
||||
if (rule && t && rule->hasCaptureAction()) {
|
||||
|
@ -45,7 +45,7 @@ bool ValidateDTD::init(const std::string &file, std::string *error) {
|
||||
|
||||
bool ValidateDTD::evaluate(Transaction *transaction, const std::string &str) {
|
||||
|
||||
XmlDtdPtrManager dtd(xmlParseDTD(NULL, (const xmlChar *)m_resource.c_str()));
|
||||
XmlDtdPtrManager dtd(xmlParseDTD(NULL, reinterpret_cast<const xmlChar *>(m_resource.c_str())));
|
||||
if (dtd.get() == NULL) {
|
||||
std::string err = std::string("XML: Failed to load DTD: ") \
|
||||
+ m_resource;
|
||||
|
@ -79,7 +79,7 @@ void XML::evaluate(Transaction *t,
|
||||
}
|
||||
|
||||
/* Process the XPath expression. */
|
||||
xpathExpr = (const xmlChar*)param.c_str();
|
||||
xpathExpr = reinterpret_cast<const xmlChar*>(param.c_str());
|
||||
xpathCtx = xmlXPathNewContext(t->m_xml->m_data.doc);
|
||||
if (xpathCtx == NULL) {
|
||||
ms_dbg_a(t, 1, "XML: Unable to create new XPath context. : ");
|
||||
@ -91,9 +91,9 @@ void XML::evaluate(Transaction *t,
|
||||
} else {
|
||||
std::vector<actions::Action *> acts = rule->getActionsByName("xmlns", t);
|
||||
for (auto &x : acts) {
|
||||
actions::XmlNS *z = (actions::XmlNS *)x;
|
||||
if (xmlXPathRegisterNs(xpathCtx, (const xmlChar*)z->m_scope.c_str(),
|
||||
(const xmlChar*)z->m_href.c_str()) != 0) {
|
||||
actions::XmlNS *z = reinterpret_cast<actions::XmlNS *>(x);
|
||||
if (xmlXPathRegisterNs(xpathCtx, reinterpret_cast<const xmlChar*>(z->m_scope.c_str()),
|
||||
reinterpret_cast<const xmlChar*>(z->m_href.c_str())) != 0) {
|
||||
ms_dbg_a(t, 1, "Failed to register XML namespace href \"" + \
|
||||
z->m_href + "\" prefix \"" + z->m_scope + "\".");
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user