From 88fb456a16de5a811298edeb253c080fb4f0b274 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Wed, 28 Dec 2016 17:46:47 -0300 Subject: [PATCH] Cosmetics: Reduces the static analysis warnings --- src/audit_log/writer/serial.h | 1 - src/operators/pm.cc | 2 - src/operators/rbl.h | 4 +- src/operators/validate_schema.h | 4 +- src/parser/driver.cc | 4 +- src/parser/driver.h | 2 - src/request_body_processor/multipart.cc | 50 +++++++++++++------------ src/request_body_processor/multipart.h | 2 +- src/utils/ip_tree.cc | 1 - test/cppcheck_suppressions.txt | 2 + test/regression/custom_debug_log.cc | 4 -- test/regression/regression.cc | 2 + 12 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/audit_log/writer/serial.h b/src/audit_log/writer/serial.h index 2ee075cf..ef08c593 100644 --- a/src/audit_log/writer/serial.h +++ b/src/audit_log/writer/serial.h @@ -49,7 +49,6 @@ class Serial : public Writer { bool write(Transaction *transaction, int parts, std::string *error) override; - private: void generateBoundary(std::string *boundary); }; diff --git a/src/operators/pm.cc b/src/operators/pm.cc index a567e391..85c3c5b4 100644 --- a/src/operators/pm.cc +++ b/src/operators/pm.cc @@ -63,7 +63,6 @@ void Pm::cleanup(acmp_node_t *n) { } free(n); - n = NULL; } @@ -76,7 +75,6 @@ void Pm::postOrderTraversal(acmp_btree_node_t *node) { postOrderTraversal(node->left); free(node); - node = NULL; } diff --git a/src/operators/rbl.h b/src/operators/rbl.h index 80ba2618..9e815562 100644 --- a/src/operators/rbl.h +++ b/src/operators/rbl.h @@ -62,8 +62,8 @@ class Rbl : public Operator { /** @ingroup ModSecurity_Operator */ Rbl(std::string op, std::string param, bool negation) : Operator(op, param, negation), - m_demandsPassword(false), - m_service(param) { + m_service(param), + m_demandsPassword(false) { m_provider = RblProvider::UnknownProvider; if (m_service == "httpbl.org") { m_demandsPassword = true; diff --git a/src/operators/validate_schema.h b/src/operators/validate_schema.h index 93b739c1..c3bf5af4 100644 --- a/src/operators/validate_schema.h +++ b/src/operators/validate_schema.h @@ -35,9 +35,9 @@ class ValidateSchema : public Operator { /** @ingroup ModSecurity_Operator */ ValidateSchema(std::string o, std::string p, bool i) : Operator(o, p, i), - m_schema(NULL), + m_parserCtx(NULL), m_validCtx(NULL), - m_parserCtx(NULL) { } + m_schema(NULL) { } ~ValidateSchema() { /* if (m_schema != NULL) { diff --git a/src/parser/driver.cc b/src/parser/driver.cc index f021de8b..08672aba 100644 --- a/src/parser/driver.cc +++ b/src/parser/driver.cc @@ -28,7 +28,8 @@ namespace Parser { Driver::Driver() : RulesProperties(), trace_scanning(false), - trace_parsing(false) { + trace_parsing(false), + lastRule(NULL) { m_auditLog = new audit_log::AuditLog(); m_auditLog->refCountIncrease(); } @@ -116,7 +117,6 @@ int Driver::addSecRule(Rule *rule) { int Driver::parse(const std::string &f, const std::string &ref) { - std::string error; lastRule = NULL; loc.push_back(new yy::location()); if (ref.empty()) { diff --git a/src/parser/driver.h b/src/parser/driver.h index 73801062..11a5ac06 100644 --- a/src/parser/driver.h +++ b/src/parser/driver.h @@ -59,8 +59,6 @@ class Driver : public RulesProperties { int addSecAction(Rule *rule); int addSecMarker(std::string marker); - int result; - bool scan_begin(); void scan_end(); bool trace_scanning; diff --git a/src/request_body_processor/multipart.cc b/src/request_body_processor/multipart.cc index 90fc49cd..ccf98e48 100644 --- a/src/request_body_processor/multipart.cc +++ b/src/request_body_processor/multipart.cc @@ -36,33 +36,35 @@ namespace RequestBodyProcessor { Multipart::Multipart(std:: string header, Transaction *transaction) - : m_boundary_count(0), + : m_reqbody_no_files_length(0), + m_nfiles(0), + m_boundary_count(0), + m_buf{0}, m_buf_contains_line(0), + m_bufptr(NULL), m_bufleft(0), m_buf_offset(0), - m_bufptr(NULL), - m_flag_boundary_quoted(0), - m_flag_boundary_whitespace(0), - m_flag_crlf_line(0), - m_flag_data_after(0), - m_flag_data_before(0), - m_flag_error(0), - m_flag_file_limit_exceeded(0), - m_flag_header_folding(0), - m_flag_invalid_header_folding(0), - m_flag_invalid_part(0), - m_flag_invalid_quoting(0), - m_flag_lf_line(0), - m_flag_missing_semicolon(0), - m_flag_unmatched_boundary(0), - m_header(header), - m_is_complete(0), + m_mpp(NULL), m_mpp_state(0), - m_nfiles(0), + m_reserve{0}, m_seen_data(0), - m_transaction(transaction), - m_reqbody_no_files_length(0) - { } + m_is_complete(0), + m_flag_error(0), + m_flag_data_before(0), + m_flag_data_after(0), + m_flag_header_folding(0), + m_flag_boundary_quoted(0), + m_flag_lf_line(0), + m_flag_crlf_line(0), + m_flag_unmatched_boundary(0), + m_flag_boundary_whitespace(0), + m_flag_missing_semicolon(0), + m_flag_invalid_quoting(0), + m_flag_invalid_part(0), + m_flag_invalid_header_folding(0), + m_flag_file_limit_exceeded(0), + m_header(header), + m_transaction(transaction) { } Multipart::~Multipart() { @@ -398,7 +400,7 @@ int Multipart::parse_content_disposition(const char *c_d_value) { } -int Multipart::tmp_file_name(std::string *filename) { +int Multipart::tmp_file_name(std::string *filename) const { std::string path; struct tm timeinfo; char tstr[300]; @@ -1197,7 +1199,7 @@ bool Multipart::init(std::string *error) { } /* Case-insensitive test for the string "boundary" in the boundary. */ - if (count_boundary_params(m_boundary.c_str()) != 0) { + if (count_boundary_params(m_boundary) != 0) { m_flag_error = 1; debug(4, "Multipart: Invalid boundary in C-T (content)."); error->assign("Multipart: Invalid boundary in C-T (content)."); diff --git a/src/request_body_processor/multipart.h b/src/request_body_processor/multipart.h index 7818625d..be1c3698 100644 --- a/src/request_body_processor/multipart.h +++ b/src/request_body_processor/multipart.h @@ -113,7 +113,7 @@ class Multipart { int process_part_header(std::string *error); int process_part_data(std::string *error); - int tmp_file_name(std::string *filename); + int tmp_file_name(std::string *filename) const; void validate_quotes(const char *data); diff --git a/src/utils/ip_tree.cc b/src/utils/ip_tree.cc index c06c9031..25e06e00 100644 --- a/src/utils/ip_tree.cc +++ b/src/utils/ip_tree.cc @@ -55,7 +55,6 @@ void IpTree::postOrderTraversal(TreeNode *node) { node->prefix = NULL; } free(node); - node = NULL; } diff --git a/test/cppcheck_suppressions.txt b/test/cppcheck_suppressions.txt index 7416ed1a..6c8deceb 100644 --- a/test/cppcheck_suppressions.txt +++ b/test/cppcheck_suppressions.txt @@ -1,3 +1,5 @@ +unusedFunction:test/regression/regression_test.cc +unusedFunction:src/utils/string.cc unusedFunction:src/transaction.cc unusedFunction:src/utils/mbedtls/sha1.c unusedFunction:src/utils/mbedtls/md5.c diff --git a/test/regression/custom_debug_log.cc b/test/regression/custom_debug_log.cc index dd14ea86..388b25d9 100644 --- a/test/regression/custom_debug_log.cc +++ b/test/regression/custom_debug_log.cc @@ -23,10 +23,6 @@ namespace modsecurity_test { -CustomDebugLog *CustomDebugLog::new_instance() { - return new CustomDebugLog(); -} - CustomDebugLog::~CustomDebugLog() { } void CustomDebugLog::write(int level, const std::string& message) { diff --git a/test/regression/regression.cc b/test/regression/regression.cc index 40251881..4233bfef 100644 --- a/test/regression/regression.cc +++ b/test/regression/regression.cc @@ -380,7 +380,9 @@ after_debug_log: int main(int argc, char **argv) { ModSecurityTest test; +#ifndef NO_LOGS int test_number = 0; +#endif #ifdef WITH_GEOIP resources.push_back("geoip");