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.
This commit is contained in:
Andrei Belov 2017-12-26 22:13:30 +03:00 committed by Felipe Zimmerle
parent 3fa3094eee
commit ebc068b8ce
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
2 changed files with 9 additions and 4 deletions

View File

@ -278,7 +278,7 @@ class ModSecurity {
ModSecurity(); ModSecurity();
~ModSecurity(); ~ModSecurity();
static const std::string whoAmI(); const std::string& whoAmI();
void setConnectorInformation(std::string connector); void setConnectorInformation(std::string connector);
void setServerLogCb(ModSecLogCb cb); void setServerLogCb(ModSecLogCb cb);
/** /**
@ -304,6 +304,7 @@ class ModSecurity {
private: private:
std::string m_connector; std::string m_connector;
std::string m_whoami;
ModSecLogCb m_logCb; ModSecLogCb m_logCb;
int m_logProperties; int m_logProperties;
}; };

View File

@ -61,6 +61,7 @@ namespace modsecurity {
*/ */
ModSecurity::ModSecurity() ModSecurity::ModSecurity()
: m_connector(""), : m_connector(""),
m_whoami(""),
#ifdef WITH_LMDB #ifdef WITH_LMDB
m_global_collection(new collection::backend::LMDB()), m_global_collection(new collection::backend::LMDB()),
m_resource_collection(new collection::backend::LMDB()), m_resource_collection(new collection::backend::LMDB()),
@ -116,7 +117,7 @@ ModSecurity::~ModSecurity() {
* update it, make it in a fashion that won't break the existent parsers. * update it, make it in a fashion that won't break the existent parsers.
* (e.g. adding extra information _only_ to the end of the string) * (e.g. adding extra information _only_ to the end of the string)
*/ */
const std::string ModSecurity::whoAmI() { const std::string& ModSecurity::whoAmI() {
std::string platform("Unknown platform"); std::string platform("Unknown platform");
#if AIX #if AIX
@ -139,8 +140,11 @@ const std::string ModSecurity::whoAmI() {
platform = "Windows"; platform = "Windows";
#endif #endif
return std::string("ModSecurity v" MODSECURITY_VERSION \ if (m_whoami.empty()) {
" (" + platform + ")"); m_whoami = "ModSecurity v" MODSECURITY_VERSION " (" + platform + ")";
}
return m_whoami;
} }