From 98a932f819e2f55dc3fafb160d55a1aa57a3d5cf Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Sun, 1 Jul 2012 20:47:07 +0200 Subject: m_dccallow Fix unsafe iteration --- src/modules/m_dccallow.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/modules/m_dccallow.cpp b/src/modules/m_dccallow.cpp index 8c2a5f73e..0c1c5a185 100644 --- a/src/modules/m_dccallow.cpp +++ b/src/modules/m_dccallow.cpp @@ -274,7 +274,9 @@ class ModuleDCCAllow : public Module // remove their DCCALLOW list if they have one if (udl) { - RemoveFromUserlist(user); + userlist::iterator it = std::find(ul.begin(), ul.end(), user); + if (it != ul.end()) + ul.erase(it); } // remove them from any DCCALLOW lists @@ -381,7 +383,7 @@ class ModuleDCCAllow : public Module void Expire() { - for (userlist::iterator iter = ul.begin(); iter != ul.end(); ++iter) + for (userlist::iterator iter = ul.begin(); iter != ul.end();) { User* u = (User*)(*iter); dl = ext->get(u); @@ -403,10 +405,11 @@ class ModuleDCCAllow : public Module } } } + ++iter; } else { - RemoveFromUserlist(u); + iter = ul.erase(iter); } } } @@ -414,7 +417,7 @@ class ModuleDCCAllow : public Module void RemoveNick(User* user) { /* Iterate through all DCCALLOW lists and remove user */ - for (userlist::iterator iter = ul.begin(); iter != ul.end(); ++iter) + for (userlist::iterator iter = ul.begin(); iter != ul.end();) { User *u = (User*)(*iter); dl = ext->get(u); @@ -434,10 +437,11 @@ class ModuleDCCAllow : public Module } } } + ++iter; } else { - RemoveFromUserlist(u); + iter = ul.erase(iter); } } } -- cgit v1.2.3