Fix a crash bug with recursion in module calls

This was found via partyline and notify_connect. notify_connect calls
CZNC::Broadcast() in OnClientLogin() which calls the OnBroadcast() module call.
When returning from this module calls, m_pUser and m_pClient was reset to NULL
and all the following modules got their OnClientLogin() called with m_pUser and
m_pClient set to NULL.

This patch fixes this by resetting those vars to their old values instead to
NULL when returning from a module call.

This patch also fixes the bug that m_pUser and m_pClient in modules were reset
to NULL after they caused a module call which called back into the current
module. The fix looks similar to the other one (this one is the Modules.h part).


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1438 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2009-03-22 19:05:34 +00:00
parent 766d775f43
commit f991274789
3 changed files with 21 additions and 9 deletions
+8 -4
View File
@@ -22,15 +22,17 @@
for (unsigned int a = 0; a < size(); a++) { \
try { \
type* pMod = (type *) (*this)[a]; \
CClient* pOldClient = pMod->GetClient(); \
pMod->SetClient(m_pClient); \
if (m_pUser) { \
CUser* pOldUser = pMod->GetUser(); \
pMod->SetUser(m_pUser); \
pMod->func; \
pMod->SetUser(NULL); \
pMod->SetUser(pOldUser); \
} else { \
pMod->func; \
} \
pMod->SetClient(NULL); \
pMod->SetClient(pOldClient); \
} catch (CModule::EModException e) { \
if (e == CModule::UNLOAD) { \
UnloadModule((*this)[a]->GetModName()); \
@@ -47,15 +49,17 @@
try { \
type* pMod = (type*) (*this)[a]; \
CModule::EModRet e = CModule::CONTINUE; \
CClient* pOldClient = pMod->GetClient(); \
pMod->SetClient(m_pClient); \
if (m_pUser) { \
CUser* pOldUser = pMod->GetUser(); \
pMod->SetUser(m_pUser); \
e = pMod->func; \
pMod->SetUser(NULL); \
pMod->SetUser(pOldUser); \
} else { \
e = pMod->func; \
} \
pMod->SetClient(NULL); \
pMod->SetClient(pOldClient); \
if (e == CModule::HALTMODS) { \
break; \
} else if (e == CModule::HALTCORE) { \