Skip to content

Commit

Permalink
Backport of relevant changes from 02859be.
Browse files Browse the repository at this point in the history
Fix undefined behavior caused by referencing the buffer returned by
std::string::c_str() when the object is temporary.
  • Loading branch information
Adam- committed Oct 5, 2012
1 parent 0566869 commit 56641d0
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/inspircd.h
Expand Up @@ -921,7 +921,7 @@ class CoreExport InspIRCd : public classbase

/** Return a time_t as a human-readable string.
*/
std::string TimeString(time_t curtime);
const std::string &TimeString(time_t curtime);

/** Begin execution of the server.
* NOTE: this function NEVER returns. Internally,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/cmd_version.cpp
Expand Up @@ -29,7 +29,8 @@ extern "C" DllExport Command* init_command(InspIRCd* Instance)

CmdResult CommandVersion::Handle (const std::vector<std::string>&, User *user)
{
user->WriteNumeric(RPL_VERSION, "%s :%s",user->nick.c_str(),ServerInstance->GetVersionString().c_str());
std::string ver = ServerInstance->GetVersionString();
user->WriteNumeric(RPL_VERSION, "%s :%s",user->nick.c_str(),ver.c_str());
ServerInstance->Config->Send005(user);
return CMD_SUCCESS;
}
6 changes: 4 additions & 2 deletions src/helperfuncs.cpp
Expand Up @@ -435,9 +435,11 @@ bool InspIRCd::SilentULine(const char* sserver)
else return false;
}

std::string InspIRCd::TimeString(time_t curtime)
const std::string &InspIRCd::TimeString(time_t curtime)
{
return std::string(ctime(&curtime),24);
static std::string buf;
buf.assign(ctime(&curtime), 24);
return buf;
}

// You should only pass a single character to this.
Expand Down
3 changes: 2 additions & 1 deletion src/modules/extra/m_ldapauth.cpp
Expand Up @@ -180,7 +180,8 @@ class ModuleLDAPAuth : public Module
size_t pos = user->password.find(":");
if (pos != std::string::npos)
{
res = ldap_search_ext_s(conn, base.c_str(), searchscope, user->password.substr(0, pos).c_str(), NULL, 0, NULL, NULL, NULL, 0, &msg);
std::string user_password = user->password.substr(0, pos);
res = ldap_search_ext_s(conn, base.c_str(), searchscope, user_password.c_str(), NULL, 0, NULL, NULL, NULL, 0, &msg);

if (res)
{
Expand Down
4 changes: 2 additions & 2 deletions src/modules/m_censor.cpp
Expand Up @@ -136,8 +136,8 @@ class ModuleCensor : public Module

for (int index = 0; index < MyConf->Enumerate("badword"); index++)
{
irc::string pattern = (MyConf->ReadValue("badword","text",index)).c_str();
irc::string replace = (MyConf->ReadValue("badword","replace",index)).c_str();
irc::string pattern = assign(MyConf->ReadValue("badword","text",index));
irc::string replace = assign(MyConf->ReadValue("badword","replace",index));
censors[pattern] = replace;
}

Expand Down
3 changes: 2 additions & 1 deletion src/modules/m_kicknorejoin.cpp
Expand Up @@ -153,7 +153,8 @@ class ModuleKickNoRejoin : public Module
{
if (iter->first == user)
{
user->WriteNumeric(ERR_DELAYREJOIN, "%s %s :You must wait %s seconds after being kicked to rejoin (+J)", user->nick.c_str(), chan->name.c_str(), chan->GetModeParameter('J').c_str());
std::string modeparam = chan->GetModeParameter('J');
user->WriteNumeric(ERR_DELAYREJOIN, "%s %s :You must wait %s seconds after being kicked to rejoin (+J)", user->nick.c_str(), chan->name.c_str(), modeparam.c_str());
return 1;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/modules/m_silence.cpp
Expand Up @@ -119,7 +119,8 @@ class CommandSilence : public Command
{
for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++)
{
user->WriteNumeric(271, "%s %s %s %s",user->nick.c_str(), user->nick.c_str(),c->first.c_str(), DecompPattern(c->second).c_str());
std::string pattern = DecompPattern(c->second);
user->WriteNumeric(271, "%s %s %s %s",user->nick.c_str(), user->nick.c_str(),c->first.c_str(), pattern.c_str());
}
}
user->WriteNumeric(272, "%s :End of Silence List",user->nick.c_str());
Expand Down

0 comments on commit 56641d0

Please sign in to comment.