From 3c18289465add11b17f33fcaf3936c3d19a00c2f Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 31 Oct 2008 08:28:08 -0500 Subject: [PATCH] Fixed race condition where client cookie callbacks could be fired against wrong clients (bug 3375). --- extensions/clientprefs/cookie.cpp | 19 +++++++++++++++++-- extensions/clientprefs/cookie.h | 2 +- extensions/clientprefs/query.cpp | 10 +++++----- extensions/clientprefs/query.h | 4 ++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/extensions/clientprefs/cookie.cpp b/extensions/clientprefs/cookie.cpp index 883eb4c39..f05c57d32 100644 --- a/extensions/clientprefs/cookie.cpp +++ b/extensions/clientprefs/cookie.cpp @@ -196,9 +196,16 @@ bool CookieManager::SetCookieValue(Cookie *pCookie, int client, char *value) void CookieManager::OnClientAuthorized(int client, const char *authstring) { + IGamePlayer *player = playerhelpers->GetGamePlayer(client); + + if (player == NULL) + { + return; + } + connected[client] = true; - TQueryOp *op = new TQueryOp(Query_SelectData, client); + TQueryOp *op = new TQueryOp(Query_SelectData, player->GetUserId()); strcpy(op->m_params.steamId, authstring); g_ClientPrefs.AddQueryToQueue(op); @@ -261,10 +268,18 @@ void CookieManager::OnClientDisconnecting(int client) } } -void CookieManager::ClientConnectCallback(int client, IQuery *data) +void CookieManager::ClientConnectCallback(int userid, IQuery *data) { + int client; IResultSet *results; + /* Check validity of client */ + if ((client = playerhelpers->GetClientOfUserId(userid)) == 0) + { + return; + } + + /* Check validity of results */ if (data == NULL || (results = data->GetResultSet()) == NULL) { return; diff --git a/extensions/clientprefs/cookie.h b/extensions/clientprefs/cookie.h index 361b746ac..c3cf75dca 100644 --- a/extensions/clientprefs/cookie.h +++ b/extensions/clientprefs/cookie.h @@ -121,7 +121,7 @@ public: void Unload(); - void ClientConnectCallback(int client, IQuery *data); + void ClientConnectCallback(int userid, IQuery *data); void InsertCookieCallback(Cookie *pCookie, int dbId); void SelectIdCallback(Cookie *pCookie, IQuery *data); diff --git a/extensions/clientprefs/query.cpp b/extensions/clientprefs/query.cpp index 7dade90e4..555699aed 100644 --- a/extensions/clientprefs/query.cpp +++ b/extensions/clientprefs/query.cpp @@ -51,7 +51,7 @@ void TQueryOp::RunThinkPart() case Query_SelectData: { - g_CookieManager.ClientConnectCallback(m_client, m_pResult); + g_CookieManager.ClientConnectCallback(m_userid, m_pResult); break; } @@ -84,10 +84,10 @@ void TQueryOp::RunThreadPart() if (!BindParamsAndRun()) { g_pSM->LogError(myself, - "Failed SQL Query, Error: \"%s\" (Query id %i - client %i)", + "Failed SQL Query, Error: \"%s\" (Query id %i - userid %i)", m_database->GetError(), m_type, - m_client); + m_userid); } m_database->UnlockFromFullAtomicOperation(); @@ -115,10 +115,10 @@ void TQueryOp::Destroy() delete this; } -TQueryOp::TQueryOp(enum querytype type, int client) +TQueryOp::TQueryOp(enum querytype type, int userid) { m_type = type; - m_client = client; + m_userid = userid; m_database = NULL; m_insertId = -1; m_pResult = NULL; diff --git a/extensions/clientprefs/query.h b/extensions/clientprefs/query.h index f09266845..29de40f2d 100644 --- a/extensions/clientprefs/query.h +++ b/extensions/clientprefs/query.h @@ -68,7 +68,7 @@ struct ParamData class TQueryOp : public IDBThreadOperation { public: - TQueryOp(enum querytype type, int client); + TQueryOp(enum querytype type, int userid); TQueryOp(enum querytype type, Cookie *cookie); ~TQueryOp() {} @@ -102,7 +102,7 @@ private: enum querytype m_type; /* Data to be passed to the callback */ - int m_client; + int m_userid; int m_insertId; Cookie *m_pCookie; };