Fix a crash bug in WebModules

WebModules use CHTTPSock for the HTTP server. That class requires a CModule
instance for working since it's based on CSocket. This was solved by creating a
fake module instance which is destroyed when the socket is destroyed.

The problem here was that CSocket's destructor tried to access that module
instance which was already destroyed resulting in a use-after-free.


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1824 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2010-03-10 19:16:38 +00:00
parent f6f7dce129
commit a7d26bb598
2 changed files with 11 additions and 7 deletions

View File

@@ -44,11 +44,15 @@ CSocket::CSocket(CModule* pModule, const CString& sHostname, unsigned short uPor
}
CSocket::~CSocket() {
CUser *pUser = m_pModule->GetUser();
CUser *pUser = NULL;
m_pModule->UnlinkSocket(this);
// CWebSock could cause us to have a NULL pointer here
if (m_pModule) {
pUser = m_pModule->GetUser();
m_pModule->UnlinkSocket(this);
}
if (!m_pModule->IsGlobal() && pUser) {
if (pUser && !m_pModule->IsGlobal()) {
pUser->AddBytesWritten(GetBytesWritten());
pUser->AddBytesRead(GetBytesRead());
} else {