Skip to content

Commit d7d5cd2

Browse files
committed
Makes m_serverIpAddress a shared pointer
1 parent 8df35de commit d7d5cd2

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

headers/modsecurity/rule_message.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class RuleMessage {
108108
int m_ruleId;
109109
int m_ruleLine;
110110
bool m_saveMessage;
111-
std::string m_serverIpAddress;
111+
std::shared_ptr<std::string> m_serverIpAddress;
112112
int m_severity;
113113
std::string m_uriNoQueryStringDecoded;
114114
std::string m_ver;

headers/modsecurity/transaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class Transaction : public TransactionAnchoredVariables {
400400
/**
401401
* Holds the server IP Address
402402
*/
403-
std::string m_serverIpAddress;
403+
std::shared_ptr<std::string> m_serverIpAddress;
404404

405405
/**
406406
* Holds the raw URI that was requested.

src/rule_message.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ std::string RuleMessage::_details(const RuleMessage *rm) {
4040
for (auto &a : rm->m_tags) {
4141
msg.append(" [tag \"" + a + "\"]");
4242
}
43-
msg.append(" [hostname \"" + std::string(rm->m_serverIpAddress) \
43+
msg.append(" [hostname \"" + *rm->m_serverIpAddress.get() \
4444
+ "\"]");
4545
msg.append(" [uri \"" + utils::string::limitTo(200, rm->m_uriNoQueryStringDecoded) + "\"]");
4646
msg.append(" [unique_id \"" + rm->m_id + "\"]");
@@ -53,7 +53,7 @@ std::string RuleMessage::_details(const RuleMessage *rm) {
5353
std::string RuleMessage::_errorLogTail(const RuleMessage *rm) {
5454
std::string msg;
5555

56-
msg.append("[hostname \"" + std::string(rm->m_serverIpAddress) + "\"]");
56+
msg.append("[hostname \"" + *rm->m_serverIpAddress.get() + "\"]");
5757
msg.append(" [uri \"" + utils::string::limitTo(200, rm->m_uriNoQueryStringDecoded) + "\"]");
5858
msg.append(" [unique_id \"" + rm->m_id + "\"]");
5959

src/transaction.cc

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ Transaction::Transaction(ModSecurity *ms, RulesSet *rules, void *logCbData)
103103
: m_creationTimeStamp(utils::cpu_seconds()),
104104
/* m_clientIpAddress(nullptr), */
105105
m_httpVersion(""),
106-
m_serverIpAddress(""),
106+
/* m_serverIpAddress(""), */
107107
m_uri(""),
108-
m_uri_no_query_string_decoded(""),
108+
/* m_uri_no_query_string_decoded(""), */
109109
m_ARGScombinedSizeDouble(0),
110110
m_clientPort(0),
111111
m_highestSeverityAction(255),
@@ -176,9 +176,9 @@ Transaction::Transaction(ModSecurity *ms, RulesSet *rules, char *id, void *logCb
176176
: m_creationTimeStamp(utils::cpu_seconds()),
177177
/* m_clientIpAddress(""), */
178178
m_httpVersion(""),
179-
m_serverIpAddress(""),
179+
/* m_serverIpAddress(""), */
180180
m_uri(""),
181-
m_uri_no_query_string_decoded(""),
181+
/* m_uri_no_query_string_decoded(""), */
182182
m_ARGScombinedSizeDouble(0),
183183
m_clientPort(0),
184184
m_highestSeverityAction(255),
@@ -310,7 +310,7 @@ void Transaction::debug(int level, std::string message) const {
310310
int Transaction::processConnection(const char *client, int cPort,
311311
const char *server, int sPort) {
312312
m_clientIpAddress = std::unique_ptr<std::string>(new std::string(client));
313-
this->m_serverIpAddress = server;
313+
m_serverIpAddress = std::unique_ptr<std::string>(new std::string(server));
314314
this->m_clientPort = cPort;
315315
this->m_serverPort = sPort;
316316
ms_dbg(4, "Transaction context created.");
@@ -320,7 +320,7 @@ int Transaction::processConnection(const char *client, int cPort,
320320
m_variableRemoteHost.set(*m_clientIpAddress.get(), m_variableOffset);
321321
m_variableUniqueID.set(m_id, m_variableOffset);
322322
m_variableRemoteAddr.set(*m_clientIpAddress.get(), m_variableOffset);
323-
m_variableServerAddr.set(m_serverIpAddress, m_variableOffset);
323+
m_variableServerAddr.set(*m_serverIpAddress.get(), m_variableOffset);
324324
m_variableServerPort.set(std::to_string(this->m_serverPort),
325325
m_variableOffset);
326326
m_variableRemotePort.set(std::to_string(this->m_clientPort),
@@ -470,9 +470,11 @@ int Transaction::processURI(const char *uri, const char *method,
470470

471471

472472
if (pos != std::string::npos) {
473-
m_uri_no_query_string_decoded = std::string(m_uri_decoded, 0, pos);
473+
m_uri_no_query_string_decoded = std::unique_ptr<std::string>(
474+
new std::string(m_uri_decoded, 0, pos));
474475
} else {
475-
m_uri_no_query_string_decoded = std::string(m_uri_decoded);
476+
m_uri_no_query_string_decoded = std::unique_ptr<std::string>(
477+
new std::string(m_uri_decoded));
476478
}
477479

478480

@@ -1523,7 +1525,7 @@ std::string Transaction::toOldAuditLogFormat(int parts,
15231525
audit_log << " " << this->m_id.c_str();
15241526
audit_log << " " << this->m_clientIpAddress;
15251527
audit_log << " " << this->m_clientPort;
1526-
audit_log << " " << this->m_serverIpAddress;
1528+
audit_log << " " << m_serverIpAddress;
15271529
audit_log << " " << this->m_serverPort;
15281530
audit_log << std::endl;
15291531

@@ -1644,7 +1646,7 @@ std::string Transaction::toJSON(int parts) {
16441646
LOGFY_ADD("time_stamp", ts.c_str());
16451647
LOGFY_ADD("server_id", uniqueId.c_str());
16461648
LOGFY_ADD_NUM("client_port", m_clientPort);
1647-
LOGFY_ADD("host_ip", m_serverIpAddress.c_str());
1649+
LOGFY_ADD("host_ip", m_serverIpAddress->c_str());
16481650
LOGFY_ADD_NUM("host_port", m_serverPort);
16491651
LOGFY_ADD("unique_id", this->m_id.c_str());
16501652

0 commit comments

Comments
 (0)