Skip to content

Commit 8df35de

Browse files
committed
Makes m_clientIpAddress a shared pointer
1 parent 196adca commit 8df35de

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

headers/modsecurity/rule_message.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class RuleMessage {
9292
static std::string _errorLogTail(const RuleMessage *rm);
9393

9494
int m_accuracy;
95-
std::string m_clientIpAddress;
95+
std::shared_ptr<std::string> m_clientIpAddress;
9696
std::string m_data;
9797
std::string m_id;
9898
bool m_isDisruptive;

headers/modsecurity/transaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class Transaction : public TransactionAnchoredVariables {
390390
/**
391391
* Holds the client IP address.
392392
*/
393-
std::string m_clientIpAddress;
393+
std::shared_ptr<std::string> m_clientIpAddress;
394394

395395
/**
396396
* Holds the HTTP version: 1.2, 2.0, 3.0 and so on....

src/rule_message.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ std::string RuleMessage::log(const RuleMessage *rm, int props, int code) {
6565
std::string msg("");
6666

6767
if (props & ClientLogMessageInfo) {
68-
msg.append("[client " + std::string(rm->m_clientIpAddress) + "] ");
68+
msg.append("[client " + std::string(*rm->m_clientIpAddress.get()) + "] ");
6969
}
7070

7171
if (rm->m_isDisruptive) {

src/transaction.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace modsecurity {
101101
*/
102102
Transaction::Transaction(ModSecurity *ms, RulesSet *rules, void *logCbData)
103103
: m_creationTimeStamp(utils::cpu_seconds()),
104-
m_clientIpAddress(""),
104+
/* m_clientIpAddress(nullptr), */
105105
m_httpVersion(""),
106106
m_serverIpAddress(""),
107107
m_uri(""),
@@ -174,7 +174,7 @@ Transaction::Transaction(ModSecurity *ms, RulesSet *rules, void *logCbData)
174174

175175
Transaction::Transaction(ModSecurity *ms, RulesSet *rules, char *id, void *logCbData)
176176
: m_creationTimeStamp(utils::cpu_seconds()),
177-
m_clientIpAddress(""),
177+
/* m_clientIpAddress(""), */
178178
m_httpVersion(""),
179179
m_serverIpAddress(""),
180180
m_uri(""),
@@ -309,17 +309,17 @@ void Transaction::debug(int level, std::string message) const {
309309
*/
310310
int Transaction::processConnection(const char *client, int cPort,
311311
const char *server, int sPort) {
312-
this->m_clientIpAddress = client;
312+
m_clientIpAddress = std::unique_ptr<std::string>(new std::string(client));
313313
this->m_serverIpAddress = server;
314314
this->m_clientPort = cPort;
315315
this->m_serverPort = sPort;
316316
ms_dbg(4, "Transaction context created.");
317317
ms_dbg(4, "Starting phase CONNECTION. (SecRules 0)");
318318

319319

320-
m_variableRemoteHost.set(m_clientIpAddress, m_variableOffset);
320+
m_variableRemoteHost.set(*m_clientIpAddress.get(), m_variableOffset);
321321
m_variableUniqueID.set(m_id, m_variableOffset);
322-
m_variableRemoteAddr.set(m_clientIpAddress, m_variableOffset);
322+
m_variableRemoteAddr.set(*m_clientIpAddress.get(), m_variableOffset);
323323
m_variableServerAddr.set(m_serverIpAddress, m_variableOffset);
324324
m_variableServerPort.set(std::to_string(this->m_serverPort),
325325
m_variableOffset);
@@ -1462,7 +1462,7 @@ std::string Transaction::toOldAuditLogFormatIndex(const std::string &filename,
14621462
ss << utils::string::dash_if_empty(
14631463
m_variableRequestHeaders.resolveFirst("Host").get())
14641464
<< " ";
1465-
ss << utils::string::dash_if_empty(this->m_clientIpAddress.c_str()) << " ";
1465+
ss << utils::string::dash_if_empty(this->m_clientIpAddress->c_str()) << " ";
14661466
/** TODO: Check variable */
14671467
variables::RemoteUser *r = new variables::RemoteUser("REMOTE_USER");
14681468
std::vector<const VariableValue *> l;
@@ -1640,7 +1640,7 @@ std::string Transaction::toJSON(int parts) {
16401640

16411641
yajl_gen_map_open(g);
16421642
/* Part: A (header mandatory) */
1643-
LOGFY_ADD("client_ip", this->m_clientIpAddress.c_str());
1643+
LOGFY_ADD("client_ip", this->m_clientIpAddress->c_str());
16441644
LOGFY_ADD("time_stamp", ts.c_str());
16451645
LOGFY_ADD("server_id", uniqueId.c_str());
16461646
LOGFY_ADD_NUM("client_port", m_clientPort);

0 commit comments

Comments
 (0)