Skip to content

Commit a5266d6

Browse files
majordawFelipe Zimmerle
authored andcommitted
Store the connection and url parameters in std::string
1 parent ba4e2e3 commit a5266d6

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

headers/modsecurity/transaction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,22 +348,22 @@ class Transaction : public TransactionAnchoredVariables {
348348
/**
349349
* Holds the client IP address.
350350
*/
351-
const char *m_clientIpAddress;
351+
std::string m_clientIpAddress;
352352

353353
/**
354354
* Holds the HTTP version: 1.2, 2.0, 3.0 and so on....
355355
*/
356-
const char *m_httpVersion;
356+
std::string m_httpVersion;
357357

358358
/**
359359
* Holds the server IP Address
360360
*/
361-
const char *m_serverIpAddress;
361+
std::string m_serverIpAddress;
362362

363363
/**
364364
* Holds the raw URI that was requested.
365365
*/
366-
const char *m_uri;
366+
std::string m_uri;
367367

368368
/**
369369
* Holds the URI that was requests (without the query string).

src/transaction.cc

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,9 @@ namespace modsecurity {
9999
*
100100
*/
101101
Transaction::Transaction(ModSecurity *ms, Rules *rules, void *logCbData)
102-
: m_clientIpAddress(""),
103-
m_serverIpAddress(""),
104-
m_clientPort(0),
102+
: m_clientPort(0),
105103
m_serverPort(0),
106-
m_uri(""),
107104
m_uri_no_query_string_decoded(""),
108-
m_httpVersion(""),
109105
m_rules(rules),
110106
m_timeStamp(std::time(NULL)),
111107
m_httpCodeReturned(200),
@@ -1355,7 +1351,7 @@ std::string Transaction::toOldAuditLogFormatIndex(const std::string &filename,
13551351
ss << utils::string::dash_if_empty(
13561352
m_variableRequestHeaders.resolveFirst("Host").get())
13571353
<< " ";
1358-
ss << utils::string::dash_if_empty(this->m_clientIpAddress) << " ";
1354+
ss << utils::string::dash_if_empty(this->m_clientIpAddress.c_str()) << " ";
13591355
/** TODO: Check variable */
13601356
ss << utils::string::dash_if_empty(
13611357
m_collections.resolveFirst("REMOTE_USER").get());
@@ -1369,8 +1365,8 @@ std::string Transaction::toOldAuditLogFormatIndex(const std::string &filename,
13691365
ss << "\"";
13701366
ss << utils::string::dash_if_empty(m_variableRequestMethod.evaluate());
13711367
ss << " ";
1372-
ss << this->m_uri << " ";
1373-
ss << "HTTP/" << m_httpVersion;
1368+
ss << this->m_uri.c_str() << " ";
1369+
ss << "HTTP/" << m_httpVersion.c_str();
13741370
ss << "\" ";
13751371

13761372
ss << this->m_httpCodeReturned << " ";
@@ -1420,8 +1416,8 @@ std::string Transaction::toOldAuditLogFormat(int parts,
14201416
audit_log << "--" << trailer << "-" << "B--" << std::endl;
14211417
audit_log << utils::string::dash_if_empty(
14221418
m_variableRequestMethod.evaluate());
1423-
audit_log << " " << this->m_uri << " " << "HTTP/";
1424-
audit_log << this->m_httpVersion << std::endl;
1419+
audit_log << " " << this->m_uri.c_str() << " " << "HTTP/";
1420+
audit_log << this->m_httpVersion.c_str() << std::endl;
14251421

14261422
m_variableRequestHeaders.resolve(&l);
14271423
for (auto &h : l) {
@@ -1459,7 +1455,7 @@ std::string Transaction::toOldAuditLogFormat(int parts,
14591455
std::vector<const collection::Variable *> l;
14601456

14611457
audit_log << "--" << trailer << "-" << "F--" << std::endl;
1462-
audit_log << "HTTP/" << m_httpVersion << " " << this->m_httpCodeReturned << std::endl;
1458+
audit_log << "HTTP/" << m_httpVersion.c_str() << " " << this->m_httpCodeReturned << std::endl;
14631459
m_variableResponseHeaders.resolve(&l);
14641460
for (auto &h : l) {
14651461
size_t pos = strlen("RESPONSE_HEADERS:");
@@ -1528,11 +1524,11 @@ std::string Transaction::toJSON(int parts) {
15281524

15291525
yajl_gen_map_open(g);
15301526
/* Part: A (header mandatory) */
1531-
LOGFY_ADD("client_ip", this->m_clientIpAddress);
1527+
LOGFY_ADD("client_ip", this->m_clientIpAddress.c_str());
15321528
LOGFY_ADD("time_stamp", ts.c_str());
15331529
LOGFY_ADD("server_id", uniqueId.c_str());
15341530
LOGFY_ADD_NUM("client_port", m_clientPort);
1535-
LOGFY_ADD("host_ip", m_serverIpAddress);
1531+
LOGFY_ADD("host_ip", m_serverIpAddress.c_str());
15361532
LOGFY_ADD_NUM("host_port", m_serverPort);
15371533
LOGFY_ADD("id", this->m_id.c_str());
15381534

@@ -1545,8 +1541,8 @@ std::string Transaction::toJSON(int parts) {
15451541
utils::string::dash_if_empty(
15461542
m_variableRequestMethod.evaluate()).c_str());
15471543

1548-
LOGFY_ADD_INT("http_version", m_httpVersion);
1549-
LOGFY_ADD("uri", this->m_uri);
1544+
LOGFY_ADD_INT("http_version", m_httpVersion.c_str());
1545+
LOGFY_ADD("uri", this->m_uri.c_str());
15501546

15511547
if (parts & audit_log::AuditLog::CAuditLogPart) {
15521548
// FIXME: check for the binary content size.

0 commit comments

Comments
 (0)