Core/Tickets: Fix memory leak when malformed CMSG_GMTICKET_CREATE is received

This commit is contained in:
Dehravor
2014-01-18 21:12:56 +01:00
parent 68af9376f6
commit e60977911a
3 changed files with 43 additions and 24 deletions

View File

@@ -49,13 +49,23 @@ void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData)
// Player must not have ticket
if (!ticket || ticket->IsClosed())
{
ticket = new GmTicket(GetPlayer(), recvData);
uint32 mapId;
float x, y, z;
std::string message;
uint32 needResponse;
bool needMoreHelp;
uint32 count;
std::list<uint32> times;
uint32 decompressedSize;
std::string chatLog;
recvData >> mapId;
recvData >> x >> y >> z;
recvData >> message;
recvData >> needResponse;
recvData >> needMoreHelp;
recvData >> count;
for (uint32 i = 0; i < count; i++)
@@ -77,19 +87,25 @@ void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData)
if (uncompress(dest.contents(), &realSize, recvData.contents() + pos, recvData.size() - pos) == Z_OK)
{
dest >> chatLog;
ticket->SetChatLog(times, chatLog);
}
else
{
TC_LOG_ERROR("network", "CMSG_GMTICKET_CREATE possibly corrupt. Uncompression failed.");
recvData.rfinish();
delete ticket;
return;
}
recvData.rfinish(); // Will still have compressed data in buffer.
}
ticket = new GmTicket(GetPlayer());
ticket->SetPosition(mapId, x, y, z);
ticket->SetMessage(message);
ticket->SetGmAction(needResponse, needMoreHelp);
if (!chatLog.empty())
ticket->SetChatLog(times, chatLog);
sTicketMgr->AddTicket(ticket);
sTicketMgr->UpdateLastChange();