mirror of
https://github.com/znc/znc.git
synced 2026-05-09 23:04:47 +02:00
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:
@@ -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
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user