From 9578b5f87a4aa96e120b78f410ea90e141903dd7 Mon Sep 17 00:00:00 2001 From: jackpoz Date: Sat, 7 Sep 2013 14:37:54 +0200 Subject: Core/Thread: Fix race condition converting time values to local time Replace thread-unsafe localtime() http://www.cplusplus.com/reference/ctime/localtime/ with thread-safe portable ACE_OS::localtime_r() . Helgrind log: Possible data race during read of size 4 at 0x6F183C0 by thread #1 Locks held: none at 0x14E72E3: World::InitDailyQuestResetTime() (World.cpp:2772) by 0x14E3A01: World::SetInitialWorldSettings() (World.cpp:1790) by 0x101122A: Master::Run() (Master.cpp:164) by 0x101740C: main (Main.cpp:142) This conflicts with a previous write of size 4 by thread #2 Locks held: none at 0x6C2D3BA: __tzfile_compute (tzfile.c:797) by 0x6C2D036: __tz_convert (tzset.c:627) by 0x164146C: LogMessage::getTimeStr(long) (Appender.cpp:23) by 0x1641550: LogMessage::getTimeStr() (Appender.cpp:31) by 0x1641722: Appender::write(LogMessage&) (Appender.cpp:80) by 0x1633FCE: Logger::write(LogMessage&) (Logger.cpp:83) by 0x16433D8: LogOperation::call() (LogOperation.cpp:29) by 0x16428A4: LogWorker::svc() (LogWorker.cpp:45) --- src/server/scripts/Commands/cs_ban.cpp | 36 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'src/server/scripts/Commands') diff --git a/src/server/scripts/Commands/cs_ban.cpp b/src/server/scripts/Commands/cs_ban.cpp index b12e058a78f..dd6e104f135 100644 --- a/src/server/scripts/Commands/cs_ban.cpp +++ b/src/server/scripts/Commands/cs_ban.cpp @@ -436,21 +436,23 @@ public: do { time_t timeBan = time_t(fields2[0].GetUInt32()); - tm* tmBan = localtime(&timeBan); + tm tmBan; + ACE_OS::localtime_r(&timeBan, &tmBan); if (fields2[0].GetUInt32() == fields2[1].GetUInt32()) { handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|", - accountName.c_str(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min, + accountName.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min, fields2[2].GetCString(), fields2[3].GetCString()); } else { time_t timeUnban = time_t(fields2[1].GetUInt32()); - tm* tmUnban = localtime(&timeUnban); + tm tmUnban; + ACE_OS::localtime_r(&timeUnban, &tmUnban); handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|", - accountName.c_str(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min, - tmUnban->tm_year%100, tmUnban->tm_mon+1, tmUnban->tm_mday, tmUnban->tm_hour, tmUnban->tm_min, + accountName.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min, + tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min, fields2[2].GetCString(), fields2[3].GetCString()); } } @@ -523,21 +525,23 @@ public: do { time_t timeBan = time_t(banFields[0].GetUInt32()); - tm* tmBan = localtime(&timeBan); + tm tmBan; + ACE_OS::localtime_r(&timeBan, &tmBan); if (banFields[0].GetUInt32() == banFields[1].GetUInt32()) { handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|", - char_name.c_str(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min, + char_name.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min, banFields[2].GetCString(), banFields[3].GetCString()); } else { time_t timeUnban = time_t(banFields[1].GetUInt32()); - tm* tmUnban = localtime(&timeUnban); + tm tmUnban; + ACE_OS::localtime_r(&timeUnban, &tmUnban); handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|", - char_name.c_str(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min, - tmUnban->tm_year%100, tmUnban->tm_mon+1, tmUnban->tm_mday, tmUnban->tm_hour, tmUnban->tm_min, + char_name.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min, + tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min, banFields[2].GetCString(), banFields[3].GetCString()); } } @@ -602,20 +606,22 @@ public: handler->SendSysMessage("-------------------------------------------------------------------------------"); Field* fields = result->Fetch(); time_t timeBan = time_t(fields[1].GetUInt32()); - tm* tmBan = localtime(&timeBan); + tm tmBan; + ACE_OS::localtime_r(&timeBan, &tmBan); if (fields[1].GetUInt32() == fields[2].GetUInt32()) { handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|", - fields[0].GetCString(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min, + fields[0].GetCString(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min, fields[3].GetCString(), fields[4].GetCString()); } else { time_t timeUnban = time_t(fields[2].GetUInt32()); - tm* tmUnban = localtime(&timeUnban); + tm tmUnban; + ACE_OS::localtime_r(&timeUnban, &tmUnban); handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|", - fields[0].GetCString(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min, - tmUnban->tm_year%100, tmUnban->tm_mon+1, tmUnban->tm_mday, tmUnban->tm_hour, tmUnban->tm_min, + fields[0].GetCString(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min, + tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min, fields[3].GetCString(), fields[4].GetCString()); } } -- cgit v1.2.3 From dfc8a092a6a81b9b11158e0efb349f5b79de092d Mon Sep 17 00:00:00 2001 From: jackpoz Date: Wed, 11 Sep 2013 20:31:50 +0200 Subject: Scripts/Commands: Retrieve Creature template in HandlePetCreateCommand from Creature itself CreatureTemplate can be retrieved directly from the Creature itself instead of using ObjectMgr::GetCreatureTemplate(id) . --- src/server/scripts/Commands/cs_pet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/server/scripts/Commands') diff --git a/src/server/scripts/Commands/cs_pet.cpp b/src/server/scripts/Commands/cs_pet.cpp index 237b25634c1..315cf06e995 100644 --- a/src/server/scripts/Commands/cs_pet.cpp +++ b/src/server/scripts/Commands/cs_pet.cpp @@ -56,7 +56,7 @@ public: return false; } - CreatureTemplate const* creatrueTemplate = sObjectMgr->GetCreatureTemplate(creatureTarget->GetEntry()); + CreatureTemplate const* creatrueTemplate = creatureTarget->GetCreatureTemplate(); // Creatures with family 0 crashes the server if (!creatrueTemplate->family) { -- cgit v1.2.3 From 3861ba5a2515f0263b927e590cd6ae3b55dbd734 Mon Sep 17 00:00:00 2001 From: Ascathor Date: Wed, 11 Sep 2013 20:54:04 +0200 Subject: Core/Commands: Fixing some problems with .account email --- src/server/scripts/Commands/cs_account.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/server/scripts/Commands') diff --git a/src/server/scripts/Commands/cs_account.cpp b/src/server/scripts/Commands/cs_account.cpp index ada26e69c14..c48eba50f72 100644 --- a/src/server/scripts/Commands/cs_account.cpp +++ b/src/server/scripts/Commands/cs_account.cpp @@ -362,9 +362,9 @@ public: return false; } - char* oldEmail = strtok(NULL, " "); + char* oldEmail = strtok((char*)args, " "); char* password = strtok(NULL, " "); - char* email = strtok((char*)args, " "); + char* email = strtok(NULL, " "); char* emailConfirmation = strtok(NULL, " "); if (!oldEmail || !password || !email || !emailConfirmation) @@ -467,6 +467,7 @@ public: handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(), handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUIDLow(), handler->HasPermission(RBAC_PERM_EMAIL_CONFIRM_FOR_PASS_CHANGE) ? "Yes" : "No"); + return false; } if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), std::string(oldPassword))) @@ -488,6 +489,7 @@ public: handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(), handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUIDLow(), emailConfirmation); + return false; } if (strcmp(newPassword, passwordConfirmation) != 0) -- cgit v1.2.3