Skip to content

Fix msc_who_am_i() to return pointer to a valid C string #1640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion headers/modsecurity/modsecurity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
/**
Expand All @@ -304,6 +304,7 @@ class ModSecurity {

private:
std::string m_connector;
std::string m_whoami;
ModSecLogCb m_logCb;
int m_logProperties;
};
Expand Down
10 changes: 7 additions & 3 deletions src/modsecurity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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
Expand All @@ -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;
}


Expand Down