From 547b603488b7a1042c6e12eb9adfa5c8fb79e75b Mon Sep 17 00:00:00 2001 From: psychon Date: Wed, 10 Mar 2010 20:47:48 +0000 Subject: [PATCH] Fix a crash bug with WebMods and auth modules When a CWebSock was destroyed before its CWebAuth, the CWebAuth dereferenced a stale pointer once it was used again. Fix this by calling CAuthBase::Invalidate() appropriately. Thanks to DarthGandalf for finding this. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1826 726aef4b-f618-498e-8847-2d620e286838 --- WebModules.cpp | 8 ++++++-- WebModules.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/WebModules.cpp b/WebModules.cpp index 5dc6da66..ebc238f6 100644 --- a/WebModules.cpp +++ b/WebModules.cpp @@ -96,6 +96,11 @@ void CWebAuth::RefusedLogin(const CString& sReason) { } } +void CWebAuth::Invalidate() { + CAuthBase::Invalidate(); + m_pWebSock = NULL; +} + CWebSock::CWebSock(CModule* pModule) : CHTTPSock(pModule) { m_pModule = pModule; m_bPathsSet = false; @@ -113,8 +118,7 @@ CWebSock::CWebSock(CModule* pModule, const CString& sHostname, unsigned short uP CWebSock::~CWebSock() { if (!m_spAuth.IsNull()) { - CWebAuth* pAuth = (CWebAuth*) &(*m_spAuth); - pAuth->SetWebSock(NULL); + m_spAuth->Invalidate(); } CUser *pUser = GetSession()->GetUser(); diff --git a/WebModules.h b/WebModules.h index b5929b40..3a3044e4 100644 --- a/WebModules.h +++ b/WebModules.h @@ -98,6 +98,7 @@ public: void SetWebSock(CWebSock* pWebSock) { m_pWebSock = pWebSock; } void AcceptedLogin(CUser& User); void RefusedLogin(const CString& sReason); + void Invalidate(); private: protected: CWebSock* m_pWebSock;