mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
webadmin/add channel: Correctly handle channel names
The CChan constructor makes sure that the channel name begins with a valid channel prefix. Thus, this could change the name of the resulting channel. When you edited an irc network which already had a channel "#foo", were connected to IRC (so ZNC knows which prefixes are valid) and added a channel "foo", this would lead to a problem: Webadmin checks and sees that there is no channel "foo" yet. Webadmin creates a new CChan instance for "foo". The CChan constructor notices that "f" is not a valid channel prefix and instead calls itself "#foo". Then, CIRCNetwork::AddChan() would see that this channel already exists, delete the given channel and return false. However, webadmin didn't check this result and would continue changing settings on an already destroyed CChan instance. Fix this by checking if the channel exists after CChan had its chance to mess with the channel name. Also handle failures from CIRCNetwork::AddChan(). Fixes #528. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
@@ -668,13 +668,19 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pNetwork->FindChan(sChanName.Token(0))) {
|
||||
WebSock.PrintErrorPage("Channel [" + sChanName.Token(0) + "] already exists");
|
||||
// This could change the channel name and e.g. add a "#" prefix
|
||||
pChan = new CChan(sChanName, pNetwork, true);
|
||||
|
||||
if (pNetwork->FindChan(pChan->GetName())) {
|
||||
WebSock.PrintErrorPage("Channel [" + pChan->GetName() + "] already exists");
|
||||
delete pChan;
|
||||
return true;
|
||||
}
|
||||
|
||||
pChan = new CChan(sChanName, pNetwork, true);
|
||||
pNetwork->AddChan(pChan);
|
||||
if (!pNetwork->AddChan(pChan)) {
|
||||
WebSock.PrintErrorPage("Could not add channel [" + pChan->GetName() + "]");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
pChan->SetBufferCount(WebSock.GetParam("buffercount").ToUInt(), spSession->IsAdmin());
|
||||
@@ -700,7 +706,7 @@ public:
|
||||
|
||||
CTemplate TmplMod;
|
||||
TmplMod["User"] = pUser->GetUserName();
|
||||
TmplMod["ChanName"] = sChanName;
|
||||
TmplMod["ChanName"] = pChan->GetName();
|
||||
TmplMod["WebadminAction"] = "change";
|
||||
FOR_EACH_MODULE(it, pNetwork) {
|
||||
(*it)->OnEmbeddedWebRequest(WebSock, "webadmin/channel", TmplMod);
|
||||
|
||||
Reference in New Issue
Block a user