From 8df35deadb16b19e4cd936e6370688dccf1e18a4 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Tue, 22 Jan 2019 14:52:18 -0300 Subject: [PATCH] Makes m_clientIpAddress a shared pointer --- headers/modsecurity/rule_message.h | 2 +- headers/modsecurity/transaction.h | 2 +- src/rule_message.cc | 2 +- src/transaction.cc | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/headers/modsecurity/rule_message.h b/headers/modsecurity/rule_message.h index 1c3dff49..5b473866 100644 --- a/headers/modsecurity/rule_message.h +++ b/headers/modsecurity/rule_message.h @@ -92,7 +92,7 @@ class RuleMessage { static std::string _errorLogTail(const RuleMessage *rm); int m_accuracy; - std::string m_clientIpAddress; + std::shared_ptr m_clientIpAddress; std::string m_data; std::string m_id; bool m_isDisruptive; diff --git a/headers/modsecurity/transaction.h b/headers/modsecurity/transaction.h index e61da71e..add4547d 100644 --- a/headers/modsecurity/transaction.h +++ b/headers/modsecurity/transaction.h @@ -390,7 +390,7 @@ class Transaction : public TransactionAnchoredVariables { /** * Holds the client IP address. */ - std::string m_clientIpAddress; + std::shared_ptr m_clientIpAddress; /** * Holds the HTTP version: 1.2, 2.0, 3.0 and so on.... diff --git a/src/rule_message.cc b/src/rule_message.cc index 7c016261..dfbaf04d 100644 --- a/src/rule_message.cc +++ b/src/rule_message.cc @@ -65,7 +65,7 @@ std::string RuleMessage::log(const RuleMessage *rm, int props, int code) { std::string msg(""); if (props & ClientLogMessageInfo) { - msg.append("[client " + std::string(rm->m_clientIpAddress) + "] "); + msg.append("[client " + std::string(*rm->m_clientIpAddress.get()) + "] "); } if (rm->m_isDisruptive) { diff --git a/src/transaction.cc b/src/transaction.cc index 61288b8f..7fa8903a 100644 --- a/src/transaction.cc +++ b/src/transaction.cc @@ -101,7 +101,7 @@ namespace modsecurity { */ Transaction::Transaction(ModSecurity *ms, RulesSet *rules, void *logCbData) : m_creationTimeStamp(utils::cpu_seconds()), - m_clientIpAddress(""), + /* m_clientIpAddress(nullptr), */ m_httpVersion(""), m_serverIpAddress(""), m_uri(""), @@ -174,7 +174,7 @@ Transaction::Transaction(ModSecurity *ms, RulesSet *rules, void *logCbData) Transaction::Transaction(ModSecurity *ms, RulesSet *rules, char *id, void *logCbData) : m_creationTimeStamp(utils::cpu_seconds()), - m_clientIpAddress(""), + /* m_clientIpAddress(""), */ m_httpVersion(""), m_serverIpAddress(""), m_uri(""), @@ -309,7 +309,7 @@ void Transaction::debug(int level, std::string message) const { */ int Transaction::processConnection(const char *client, int cPort, const char *server, int sPort) { - this->m_clientIpAddress = client; + m_clientIpAddress = std::unique_ptr(new std::string(client)); this->m_serverIpAddress = server; this->m_clientPort = cPort; this->m_serverPort = sPort; @@ -317,9 +317,9 @@ int Transaction::processConnection(const char *client, int cPort, ms_dbg(4, "Starting phase CONNECTION. (SecRules 0)"); - m_variableRemoteHost.set(m_clientIpAddress, m_variableOffset); + m_variableRemoteHost.set(*m_clientIpAddress.get(), m_variableOffset); m_variableUniqueID.set(m_id, m_variableOffset); - m_variableRemoteAddr.set(m_clientIpAddress, m_variableOffset); + m_variableRemoteAddr.set(*m_clientIpAddress.get(), m_variableOffset); m_variableServerAddr.set(m_serverIpAddress, m_variableOffset); m_variableServerPort.set(std::to_string(this->m_serverPort), m_variableOffset); @@ -1462,7 +1462,7 @@ std::string Transaction::toOldAuditLogFormatIndex(const std::string &filename, ss << utils::string::dash_if_empty( m_variableRequestHeaders.resolveFirst("Host").get()) << " "; - ss << utils::string::dash_if_empty(this->m_clientIpAddress.c_str()) << " "; + ss << utils::string::dash_if_empty(this->m_clientIpAddress->c_str()) << " "; /** TODO: Check variable */ variables::RemoteUser *r = new variables::RemoteUser("REMOTE_USER"); std::vector l; @@ -1640,7 +1640,7 @@ std::string Transaction::toJSON(int parts) { yajl_gen_map_open(g); /* Part: A (header mandatory) */ - LOGFY_ADD("client_ip", this->m_clientIpAddress.c_str()); + LOGFY_ADD("client_ip", this->m_clientIpAddress->c_str()); LOGFY_ADD("time_stamp", ts.c_str()); LOGFY_ADD("server_id", uniqueId.c_str()); LOGFY_ADD_NUM("client_port", m_clientPort);