From e3efb6a0f69203929d9042f9a7b14ba81cf71ddb Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Sat, 8 Dec 2012 16:14:19 +0100 Subject: Fix unsafe iteration in DelMode() when unloading m_permchannels --- src/mode.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/mode.cpp') diff --git a/src/mode.cpp b/src/mode.cpp index 0957184b7..35f64ce00 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -675,15 +675,20 @@ bool ModeParser::DelMode(ModeHandler* mh) switch (mh->GetModeType()) { case MODETYPE_USER: - for (user_hash::iterator i = ServerInstance->Users->clientlist->begin(); i != ServerInstance->Users->clientlist->end(); i++) + for (user_hash::iterator i = ServerInstance->Users->clientlist->begin(); i != ServerInstance->Users->clientlist->end(); ) { - mh->RemoveMode(i->second); + User* user = i->second; + ++i; + mh->RemoveMode(user); } break; case MODETYPE_CHANNEL: - for (chan_hash::iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++) + for (chan_hash::iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); ) { - mh->RemoveMode(i->second); + // The channel may not be in the hash after RemoveMode(), see m_permchannels + Channel* chan = i->second; + ++i; + mh->RemoveMode(chan); } break; } -- cgit v1.2.3