Fix a crash with WebMods and deleting User

If a user who is currently logged in to WebMods is deleted, his CWebSession
still kept a stale CUser pointer around. The next time he loaded a web page,
Bad Things(tm) happened.

This is fixed by deleting all of a user's sessions when that user is deleted.

Thanks to DarthGandalf for spotting the bug and writing the patch.


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1827 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2010-03-11 17:29:36 +00:00
parent a74c2a4625
commit 4303c3c200
4 changed files with 24 additions and 3 deletions
+1 -1
View File
@@ -358,7 +358,7 @@ public:
// Getters
unsigned int GetTTL() { return m_uTTL; }
// !Getters
private:
protected:
typedef pair<unsigned long long, V> value;
typedef typename map<K, value>::iterator iterator;
map<K, value> m_mItems; //!< Map of cached items. The value portion of the map is for the expire time
+12 -1
View File
@@ -12,7 +12,7 @@
#include <sstream>
// Sessions are valid for a day, (24h, ...)
TCacheMap<CString, CSmartPtr<CWebSession> > CWebSock::m_mspSessions(24 * 60 * 60 * 1000);
CWebSessionMap CWebSock::m_mspSessions(24 * 60 * 60 * 1000);
CZNCTagHandler::CZNCTagHandler(CWebSock& WebSock) : CTemplateTagHandler(), m_WebSock(WebSock) {
}
@@ -66,6 +66,17 @@ size_t CWebSession::AddSuccess(const CString& sMessage) {
return m_vsSuccessMsgs.size();
}
void CWebSessionMap::FinishUserSessions(const CUser& User) {
iterator it = m_mItems.begin();
while (it != m_mItems.end()) {
if (it->second.second->GetUser() == &User) {
m_mItems.erase(it++);
} else {
++it;
}
}
}
void CWebAuth::AcceptedLogin(CUser& User) {
if (m_pWebSock) {
+10 -1
View File
@@ -104,6 +104,11 @@ protected:
CWebSock* m_pWebSock;
};
class CWebSessionMap : public TCacheMap<CString, CSmartPtr<CWebSession> > {
public:
CWebSessionMap(unsigned int uTTL = 5000) : TCacheMap<CString, CSmartPtr<CWebSession> >(uTTL) {}
void FinishUserSessions(const CUser& User);
};
class CWebSock : public CHTTPSock {
public:
@@ -148,6 +153,10 @@ public:
CString GetCookie(const CString& sKey) const;
bool SetCookie(const CString& sKey, const CString& sValue);
static void FinishUserSessions(const CUser& User) {
m_mspSessions.FinishUserSessions(User);
}
private:
bool m_bPathsSet;
CTemplate m_Template;
@@ -158,7 +167,7 @@ private:
CString m_sPage; // Gets filled by ResolveModule()
CSmartPtr<CWebSession> m_spSession;
static TCacheMap<CString, CSmartPtr<CWebSession> > m_mspSessions;
static CWebSessionMap m_mspSessions;
};
#endif // !_WEBMODULES_H
+1
View File
@@ -208,6 +208,7 @@ bool CZNC::HandleUserDeletion()
pUser->DelClients();
pUser->DelModules();
CWebSock::FinishUserSessions(*pUser);
AddBytesRead(pUser->BytesRead());
AddBytesWritten(pUser->BytesWritten());
delete pUser;