summaryrefslogtreecommitdiff
path: root/src/modules/m_spanningtree
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2012-09-30 01:10:57 +0200
committerattilamolnar <attilamolnar@hush.com>2012-09-30 03:04:07 +0200
commit02859be56d43bcece02aab350e02bc95ed1bf446 (patch)
treebbb68a91e26f4502c22047ad2b26ed8918c5fbb1 /src/modules/m_spanningtree
parent83e90c4baa1215caf05295aec86a0a4d7bfff3f9 (diff)
Fix more undefined behavior caused by referencing the returned buffer by std::string::c_str() when the object is temporary
See 83c7cc45daf6fb1f8c36f15297a4657e45a34e88
Diffstat (limited to 'src/modules/m_spanningtree')
-rw-r--r--src/modules/m_spanningtree/addline.cpp8
-rw-r--r--src/modules/m_spanningtree/delline.cpp2
-rw-r--r--src/modules/m_spanningtree/main.cpp15
-rw-r--r--src/modules/m_spanningtree/netburst.cpp4
-rw-r--r--src/modules/m_spanningtree/override_map.cpp7
-rw-r--r--src/modules/m_spanningtree/treesocket1.cpp3
-rw-r--r--src/modules/m_spanningtree/treesocket2.cpp5
7 files changed, 28 insertions, 16 deletions
diff --git a/src/modules/m_spanningtree/addline.cpp b/src/modules/m_spanningtree/addline.cpp
index 5c3ad548d..7ee1a7ef1 100644
--- a/src/modules/m_spanningtree/addline.cpp
+++ b/src/modules/m_spanningtree/addline.cpp
@@ -30,7 +30,8 @@ bool TreeSocket::AddLine(const std::string &prefix, parameterlist &params)
{
if (params.size() < 6)
{
- ServerInstance->SNO->WriteToSnoMask('d', "%s sent me a malformed ADDLINE", MyRoot->GetName().c_str());
+ std::string servername = MyRoot->GetName();
+ ServerInstance->SNO->WriteToSnoMask('d', "%s sent me a malformed ADDLINE", servername.c_str());
return true;
}
@@ -44,7 +45,7 @@ bool TreeSocket::AddLine(const std::string &prefix, parameterlist &params)
{
TreeServer* t = Utils->FindServer(prefix);
if (t)
- setter = t->GetName().c_str();
+ setter = t->GetName();
}
if (!xlf)
@@ -68,8 +69,9 @@ bool TreeSocket::AddLine(const std::string &prefix, parameterlist &params)
{
if (xl->duration)
{
+ std::string timestr = ServerInstance->TimeString(xl->expiry);
ServerInstance->SNO->WriteToSnoMask('X',"%s added %s%s on %s to expire on %s: %s",setter.c_str(),params[0].c_str(),params[0].length() == 1 ? "-line" : "",
- params[1].c_str(),ServerInstance->TimeString(xl->expiry).c_str(),params[5].c_str());
+ params[1].c_str(), timestr.c_str(), params[5].c_str());
}
else
{
diff --git a/src/modules/m_spanningtree/delline.cpp b/src/modules/m_spanningtree/delline.cpp
index 5d88b4a0b..540ca5079 100644
--- a/src/modules/m_spanningtree/delline.cpp
+++ b/src/modules/m_spanningtree/delline.cpp
@@ -41,7 +41,7 @@ bool TreeSocket::DelLine(const std::string &prefix, parameterlist &params)
{
TreeServer* t = Utils->FindServer(prefix);
if (t)
- setter = t->GetName().c_str();
+ setter = t->GetName();
}
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index f639a748d..1ccfc43a5 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -99,7 +99,7 @@ void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops)
}
for (unsigned int q = 0; q < Current->ChildCount(); q++)
{
- if ((Current->GetChild(q)->Hidden) || ((Utils->HideULines) && (ServerInstance->ULine(Current->GetChild(q)->GetName().c_str()))))
+ if ((Current->GetChild(q)->Hidden) || ((Utils->HideULines) && (ServerInstance->ULine(Current->GetChild(q)->GetName()))))
{
if (IS_OPER(user))
{
@@ -112,13 +112,14 @@ void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops)
}
}
/* Don't display the line if its a uline, hide ulines is on, and the user isnt an oper */
- if ((Utils->HideULines) && (ServerInstance->ULine(Current->GetName().c_str())) && (!IS_OPER(user)))
+ if ((Utils->HideULines) && (ServerInstance->ULine(Current->GetName())) && (!IS_OPER(user)))
return;
/* Or if the server is hidden and they're not an oper */
else if ((Current->Hidden) && (!IS_OPER(user)))
return;
- user->WriteNumeric(364, "%s %s %s :%d %s", user->nick.c_str(),Current->GetName().c_str(),
+ std::string servername = Current->GetName();
+ user->WriteNumeric(364, "%s %s %s :%d %s", user->nick.c_str(), servername.c_str(),
(Utils->FlatLinks && (!IS_OPER(user))) ? ServerInstance->Config->ServerName.c_str() : Parent.c_str(),
(Utils->FlatLinks && (!IS_OPER(user))) ? 0 : hops,
Current->GetDesc().c_str());
@@ -162,7 +163,7 @@ restart:
for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
{
TreeServer *s = i->second;
-
+
if (s->GetSocket() && s->GetSocket()->GetLinkState() == DYING)
{
s->GetSocket()->Close();
@@ -215,7 +216,8 @@ restart:
if ((Utils->PingWarnTime) && (!s->Warned) && (curtime >= s->NextPingTime() - (Utils->PingFreq - Utils->PingWarnTime)) && (!s->AnsweredLastPing()))
{
/* The server hasnt responded, send a warning to opers */
- ServerInstance->SNO->WriteToSnoMask('l',"Server \002%s\002 has not responded to PING for %d seconds, high latency.", s->GetName().c_str(), Utils->PingWarnTime);
+ std::string servername = s->GetName();
+ ServerInstance->SNO->WriteToSnoMask('l',"Server \002%s\002 has not responded to PING for %d seconds, high latency.", servername.c_str(), Utils->PingWarnTime);
s->Warned = true;
}
}
@@ -411,7 +413,8 @@ ModResult ModuleSpanningTree::HandleConnect(const std::vector<std::string>& para
}
else
{
- RemoteMessage(user, "*** CONNECT: Server \002%s\002 already exists on the network and is connected via \002%s\002",x->Name.c_str(),CheckDupe->GetParent()->GetName().c_str());
+ std::string servername = CheckDupe->GetParent()->GetName();
+ RemoteMessage(user, "*** CONNECT: Server \002%s\002 already exists on the network and is connected via \002%s\002", x->Name.c_str(), servername.c_str());
return MOD_RES_DENY;
}
}
diff --git a/src/modules/m_spanningtree/netburst.cpp b/src/modules/m_spanningtree/netburst.cpp
index b1b55c986..8cd0dccd9 100644
--- a/src/modules/m_spanningtree/netburst.cpp
+++ b/src/modules/m_spanningtree/netburst.cpp
@@ -74,7 +74,9 @@ void TreeSocket::SendServers(TreeServer* Current, TreeServer* s, int hops)
TreeServer* recursive_server = Current->GetChild(q);
if (recursive_server != s)
{
- snprintf(command,1024,":%s SERVER %s * %d %s :%s",Current->GetName().c_str(),recursive_server->GetName().c_str(),hops,
+ std::string servername = Current->GetName();
+ std::string recursive_servername = recursive_server->GetName();
+ snprintf(command,1024,":%s SERVER %s * %d %s :%s", servername.c_str(), recursive_servername.c_str(), hops,
recursive_server->GetID().c_str(),
recursive_server->GetDesc().c_str());
this->WriteLine(command);
diff --git a/src/modules/m_spanningtree/override_map.cpp b/src/modules/m_spanningtree/override_map.cpp
index 83d969b3f..04fa4bcab 100644
--- a/src/modules/m_spanningtree/override_map.cpp
+++ b/src/modules/m_spanningtree/override_map.cpp
@@ -58,13 +58,14 @@ void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, int
memset(myname, ' ', depth);
int w = depth;
+ std::string servername = Current->GetName();
if (IS_OPER(user))
{
- w += snprintf(myname + depth, 99 - depth, "%s (%s)", Current->GetName().c_str(), Current->GetID().c_str());
+ w += snprintf(myname + depth, 99 - depth, "%s (%s)", servername.c_str(), Current->GetID().c_str());
}
else
{
- w += snprintf(myname + depth, 99 - depth, "%s", Current->GetName().c_str());
+ w += snprintf(myname + depth, 99 - depth, "%s", servername.c_str());
}
memset(myname + w, ' ', 100 - w);
if (w > maxnamew)
@@ -81,7 +82,7 @@ void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, int
if (!IS_OPER(user)) {
if (child->Hidden)
continue;
- if ((Utils->HideULines) && (ServerInstance->ULine(child->GetName().c_str())))
+ if ((Utils->HideULines) && (ServerInstance->ULine(child->GetName())))
continue;
}
ShowMap(child, user, depth, line, names, maxnamew, stats);
diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp
index 3e916544b..6582ba060 100644
--- a/src/modules/m_spanningtree/treesocket1.cpp
+++ b/src/modules/m_spanningtree/treesocket1.cpp
@@ -157,8 +157,9 @@ void TreeSocket::SendError(const std::string &errormessage)
*/
void TreeSocket::SquitServer(std::string &from, TreeServer* Current, int& num_lost_servers, int& num_lost_users)
{
+ std::string servername = Current->GetName();
ServerInstance->Logs->Log("m_spanningtree",DEBUG,"SquitServer for %s from %s",
- Current->GetName().c_str(), from.c_str());
+ servername.c_str(), from.c_str());
/* recursively squit the servers attached to 'Current'.
* We're going backwards so we don't remove users
* while we still need them ;)
diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp
index 0a0c22e39..a06ff3a67 100644
--- a/src/modules/m_spanningtree/treesocket2.cpp
+++ b/src/modules/m_spanningtree/treesocket2.cpp
@@ -491,6 +491,9 @@ void TreeSocket::Close()
time_t server_uptime = ServerInstance->Time() - this->age;
if (server_uptime)
- ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\2%s\2' was established for %s", linkID.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
+ {
+ std::string timestr = Utils->Creator->TimeToStr(server_uptime);
+ ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\2%s\2' was established for %s", linkID.c_str(), timestr.c_str());
+ }
}
}