From 75441ddb3b94f207345d1646a991a57cb00698dd Mon Sep 17 00:00:00 2001 From: Jelle Meeus Date: Fri, 14 Feb 2025 15:45:36 +0100 Subject: [PATCH] fix(Core/Player): SpellQueue avoid possible undefined behavior by copying instead of move (#21444) --- src/server/game/Handlers/SpellHandler.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/server/game/Handlers/SpellHandler.cpp b/src/server/game/Handlers/SpellHandler.cpp index 7f11d413f..e200aaf3d 100644 --- a/src/server/game/Handlers/SpellHandler.cpp +++ b/src/server/game/Handlers/SpellHandler.cpp @@ -110,11 +110,12 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket) if (!_player->CanExecutePendingSpellCastRequest(spellInfo)) if (_player->CanRequestSpellCast(spellInfo)) { - recvPacket.rpos(0); // Reset read position to the start of the buffer. + WorldPacket packetCopy(recvPacket); // Copy the packet + packetCopy.rpos(0); // Reset read position to the start of the buffer. _player->SpellQueue.emplace_back( spellId, spellInfo->GetCategory(), - std::move(recvPacket), // Move ownership of recvPacket + std::move(packetCopy), // Move ownership of copied packet true // itemCast ); return; @@ -424,11 +425,12 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket) { if (_player->CanRequestSpellCast(spellInfo)) { - recvPacket.rpos(0); // Reset read position to the start of the buffer. + WorldPacket packetCopy(recvPacket); // Copy the packet + packetCopy.rpos(0); // Reset read position to the start of the buffer. _player->SpellQueue.emplace_back( spellId, spellInfo->GetCategory(), - std::move(recvPacket) // Move ownership of recvPacket + std::move(packetCopy) // Move ownership of copied packet ); return; }