diff options
author | attilamolnar <attilamolnar@hush.com> | 2012-09-23 02:51:16 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2012-09-23 03:16:58 +0200 |
commit | 83c7cc45daf6fb1f8c36f15297a4657e45a34e88 (patch) | |
tree | c29ad7d8623eb7789c39c519de19ee414db2a95e /src/configreader.cpp | |
parent | cff57f7ba780a5c4fc331ccbab489abdc572379c (diff) |
Fix undefined behavior caused by referencing the returned buffer by std::string::c_str() when the object is temporary
Thanks to @ChrisTX for pointing this out
Fixes #257 reported by @helloall
Diffstat (limited to 'src/configreader.cpp')
-rw-r--r-- | src/configreader.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp index 37742cc9f..b5db19fa1 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -576,22 +576,25 @@ void ServerConfig::Fill() ReadXLine(this, "exception", "host", ServerInstance->XLines->GetFactory("E")); memset(DisabledUModes, 0, sizeof(DisabledUModes)); - for (const unsigned char* p = (const unsigned char*)ConfValue("disabled")->getString("usermodes").c_str(); *p; ++p) + std::string modes = ConfValue("disabled")->getString("usermodes"); + for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p) { if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid usermode ")+(char)*p+" was found."); DisabledUModes[*p - 'A'] = 1; } memset(DisabledCModes, 0, sizeof(DisabledCModes)); - for (const unsigned char* p = (const unsigned char*)ConfValue("disabled")->getString("chanmodes").c_str(); *p; ++p) + modes = ConfValue("disabled")->getString("chanmodes"); + for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p) { if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid chanmode ")+(char)*p+" was found."); DisabledCModes[*p - 'A'] = 1; } memset(HideModeLists, 0, sizeof(HideModeLists)); - for (const unsigned char* p = (const unsigned char*)ConfValue("security")->getString("hidemodes").c_str(); *p; ++p) - HideModeLists[*p] = true; + modes = ConfValue("security")->getString("hidemodes"); + for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p) + HideModeLists[(unsigned char) *p] = true; std::string v = security->getString("announceinvites"); |