diff --git a/headers/modsecurity/rule_message.h b/headers/modsecurity/rule_message.h index 5b473866..1d186d50 100644 --- a/headers/modsecurity/rule_message.h +++ b/headers/modsecurity/rule_message.h @@ -108,7 +108,7 @@ class RuleMessage { int m_ruleId; int m_ruleLine; bool m_saveMessage; - std::string m_serverIpAddress; + std::shared_ptr m_serverIpAddress; int m_severity; std::string m_uriNoQueryStringDecoded; std::string m_ver; diff --git a/headers/modsecurity/transaction.h b/headers/modsecurity/transaction.h index add4547d..5a533cda 100644 --- a/headers/modsecurity/transaction.h +++ b/headers/modsecurity/transaction.h @@ -400,7 +400,7 @@ class Transaction : public TransactionAnchoredVariables { /** * Holds the server IP Address */ - std::string m_serverIpAddress; + std::shared_ptr m_serverIpAddress; /** * Holds the raw URI that was requested. diff --git a/src/rule_message.cc b/src/rule_message.cc index dfbaf04d..ec021e6a 100644 --- a/src/rule_message.cc +++ b/src/rule_message.cc @@ -40,7 +40,7 @@ std::string RuleMessage::_details(const RuleMessage *rm) { for (auto &a : rm->m_tags) { msg.append(" [tag \"" + a + "\"]"); } - msg.append(" [hostname \"" + std::string(rm->m_serverIpAddress) \ + msg.append(" [hostname \"" + *rm->m_serverIpAddress.get() \ + "\"]"); msg.append(" [uri \"" + utils::string::limitTo(200, rm->m_uriNoQueryStringDecoded) + "\"]"); msg.append(" [unique_id \"" + rm->m_id + "\"]"); @@ -53,7 +53,7 @@ std::string RuleMessage::_details(const RuleMessage *rm) { std::string RuleMessage::_errorLogTail(const RuleMessage *rm) { std::string msg; - msg.append("[hostname \"" + std::string(rm->m_serverIpAddress) + "\"]"); + msg.append("[hostname \"" + *rm->m_serverIpAddress.get() + "\"]"); msg.append(" [uri \"" + utils::string::limitTo(200, rm->m_uriNoQueryStringDecoded) + "\"]"); msg.append(" [unique_id \"" + rm->m_id + "\"]"); diff --git a/src/transaction.cc b/src/transaction.cc index 7fa8903a..e4879077 100644 --- a/src/transaction.cc +++ b/src/transaction.cc @@ -103,9 +103,9 @@ Transaction::Transaction(ModSecurity *ms, RulesSet *rules, void *logCbData) : m_creationTimeStamp(utils::cpu_seconds()), /* m_clientIpAddress(nullptr), */ m_httpVersion(""), - m_serverIpAddress(""), + /* m_serverIpAddress(""), */ m_uri(""), - m_uri_no_query_string_decoded(""), + /* m_uri_no_query_string_decoded(""), */ m_ARGScombinedSizeDouble(0), m_clientPort(0), m_highestSeverityAction(255), @@ -176,9 +176,9 @@ Transaction::Transaction(ModSecurity *ms, RulesSet *rules, char *id, void *logCb : m_creationTimeStamp(utils::cpu_seconds()), /* m_clientIpAddress(""), */ m_httpVersion(""), - m_serverIpAddress(""), + /* m_serverIpAddress(""), */ m_uri(""), - m_uri_no_query_string_decoded(""), + /* m_uri_no_query_string_decoded(""), */ m_ARGScombinedSizeDouble(0), m_clientPort(0), m_highestSeverityAction(255), @@ -310,7 +310,7 @@ void Transaction::debug(int level, std::string message) const { int Transaction::processConnection(const char *client, int cPort, const char *server, int sPort) { m_clientIpAddress = std::unique_ptr(new std::string(client)); - this->m_serverIpAddress = server; + m_serverIpAddress = std::unique_ptr(new std::string(server)); this->m_clientPort = cPort; this->m_serverPort = sPort; ms_dbg(4, "Transaction context created."); @@ -320,7 +320,7 @@ int Transaction::processConnection(const char *client, int cPort, m_variableRemoteHost.set(*m_clientIpAddress.get(), m_variableOffset); m_variableUniqueID.set(m_id, m_variableOffset); m_variableRemoteAddr.set(*m_clientIpAddress.get(), m_variableOffset); - m_variableServerAddr.set(m_serverIpAddress, m_variableOffset); + m_variableServerAddr.set(*m_serverIpAddress.get(), m_variableOffset); m_variableServerPort.set(std::to_string(this->m_serverPort), m_variableOffset); m_variableRemotePort.set(std::to_string(this->m_clientPort), @@ -470,9 +470,11 @@ int Transaction::processURI(const char *uri, const char *method, if (pos != std::string::npos) { - m_uri_no_query_string_decoded = std::string(m_uri_decoded, 0, pos); + m_uri_no_query_string_decoded = std::unique_ptr( + new std::string(m_uri_decoded, 0, pos)); } else { - m_uri_no_query_string_decoded = std::string(m_uri_decoded); + m_uri_no_query_string_decoded = std::unique_ptr( + new std::string(m_uri_decoded)); } @@ -1523,7 +1525,7 @@ std::string Transaction::toOldAuditLogFormat(int parts, audit_log << " " << this->m_id.c_str(); audit_log << " " << this->m_clientIpAddress; audit_log << " " << this->m_clientPort; - audit_log << " " << this->m_serverIpAddress; + audit_log << " " << m_serverIpAddress; audit_log << " " << this->m_serverPort; audit_log << std::endl; @@ -1644,7 +1646,7 @@ std::string Transaction::toJSON(int parts) { LOGFY_ADD("time_stamp", ts.c_str()); LOGFY_ADD("server_id", uniqueId.c_str()); LOGFY_ADD_NUM("client_port", m_clientPort); - LOGFY_ADD("host_ip", m_serverIpAddress.c_str()); + LOGFY_ADD("host_ip", m_serverIpAddress->c_str()); LOGFY_ADD_NUM("host_port", m_serverPort); LOGFY_ADD("unique_id", this->m_id.c_str());