From f06df087a7c1f156195c065d2ec41b055f902a43 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 | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/headers/modsecurity/rule_message.h b/headers/modsecurity/rule_message.h index 2362a607..5c4c7e6d 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 a528faee..2b0eb47f 100644 --- a/headers/modsecurity/transaction.h +++ b/headers/modsecurity/transaction.h @@ -386,7 +386,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 4255e53e..cf26c8d2 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 1aa2db5c..29dc63b9 100644 --- a/src/transaction.cc +++ b/src/transaction.cc @@ -250,7 +250,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; @@ -258,9 +258,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); @@ -1353,7 +1353,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; @@ -1532,7 +1532,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);