From 0afcc79085c2f483878c4e986cced106d00fe1dd Mon Sep 17 00:00:00 2001 From: Andrei Belov Date: Tue, 26 Dec 2017 22:13:30 +0300 Subject: [PATCH] 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. --- headers/modsecurity/modsecurity.h | 3 ++- src/modsecurity.cc | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/headers/modsecurity/modsecurity.h b/headers/modsecurity/modsecurity.h index a9265b65e1..299f1c0159 100644 --- a/headers/modsecurity/modsecurity.h +++ b/headers/modsecurity/modsecurity.h @@ -278,7 +278,7 @@ class ModSecurity { ModSecurity(); ~ModSecurity(); - static const std::string whoAmI(); + const std::string& whoAmI(); void setConnectorInformation(std::string connector); void setServerLogCb(ModSecLogCb cb); /** @@ -304,6 +304,7 @@ class ModSecurity { private: std::string m_connector; + std::string m_whoami; ModSecLogCb m_logCb; int m_logProperties; }; diff --git a/src/modsecurity.cc b/src/modsecurity.cc index d58b607525..e246d96f33 100644 --- a/src/modsecurity.cc +++ b/src/modsecurity.cc @@ -59,6 +59,7 @@ namespace modsecurity { */ ModSecurity::ModSecurity() : m_connector(""), + m_whoami(""), #ifdef WITH_LMDB m_global_collection(new collection::backend::LMDB()), m_resource_collection(new collection::backend::LMDB()), @@ -111,7 +112,7 @@ ModSecurity::~ModSecurity() { * 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) */ -const std::string ModSecurity::whoAmI() { +const std::string& ModSecurity::whoAmI() { std::string platform("Unknown platform"); #if AIX @@ -134,8 +135,11 @@ const std::string ModSecurity::whoAmI() { platform = "Windows"; #endif - return std::string("ModSecurity v" MODSECURITY_VERSION \ - " (" + platform + ")"); + if (m_whoami.empty()) { + m_whoami = "ModSecurity v" MODSECURITY_VERSION " (" + platform + ")"; + } + + return m_whoami; }