Skip to content

Commit ebc068b

Browse files
defanatorFelipe Zimmerle
authored and
Felipe Zimmerle
committed
Fix msc_who_am_i() to return pointer to a valid C string
Previously this function was unusable as it returned pointer to some garbage data.
1 parent 3fa3094 commit ebc068b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

headers/modsecurity/modsecurity.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class ModSecurity {
278278
ModSecurity();
279279
~ModSecurity();
280280

281-
static const std::string whoAmI();
281+
const std::string& whoAmI();
282282
void setConnectorInformation(std::string connector);
283283
void setServerLogCb(ModSecLogCb cb);
284284
/**
@@ -304,6 +304,7 @@ class ModSecurity {
304304

305305
private:
306306
std::string m_connector;
307+
std::string m_whoami;
307308
ModSecLogCb m_logCb;
308309
int m_logProperties;
309310
};

src/modsecurity.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ namespace modsecurity {
6161
*/
6262
ModSecurity::ModSecurity()
6363
: m_connector(""),
64+
m_whoami(""),
6465
#ifdef WITH_LMDB
6566
m_global_collection(new collection::backend::LMDB()),
6667
m_resource_collection(new collection::backend::LMDB()),
@@ -116,7 +117,7 @@ ModSecurity::~ModSecurity() {
116117
* update it, make it in a fashion that won't break the existent parsers.
117118
* (e.g. adding extra information _only_ to the end of the string)
118119
*/
119-
const std::string ModSecurity::whoAmI() {
120+
const std::string& ModSecurity::whoAmI() {
120121
std::string platform("Unknown platform");
121122

122123
#if AIX
@@ -139,8 +140,11 @@ const std::string ModSecurity::whoAmI() {
139140
platform = "Windows";
140141
#endif
141142

142-
return std::string("ModSecurity v" MODSECURITY_VERSION \
143-
" (" + platform + ")");
143+
if (m_whoami.empty()) {
144+
m_whoami = "ModSecurity v" MODSECURITY_VERSION " (" + platform + ")";
145+
}
146+
147+
return m_whoami;
144148
}
145149

146150

0 commit comments

Comments
 (0)