diff --git a/src/game/ObjectGuid.cpp b/src/game/ObjectGuid.cpp index 91d2f0d7a..bc6453a68 100644 --- a/src/game/ObjectGuid.cpp +++ b/src/game/ObjectGuid.cpp @@ -72,6 +72,11 @@ std::string ObjectGuid::GetString() const return str.str(); } +void ObjectGuid::Set(uint64 const& guid) +{ + m_guid = guid; +} + template uint32 ObjectGuidGenerator::Generate() { @@ -111,7 +116,9 @@ ByteBuffer& operator<< (ByteBuffer& buf, ObjectGuid const& guid) ByteBuffer &operator>>(ByteBuffer& buf, ObjectGuid& guid) { - guid.Set(buf.read()); + uint64 value = buf.read(); + ObjectGuid::ClampPlayerGuid(value); + guid.Set(value); return buf; } @@ -123,10 +130,24 @@ ByteBuffer& operator<< (ByteBuffer& buf, PackedGuid const& guid) ByteBuffer &operator>>(ByteBuffer& buf, PackedGuidReader const& guid) { - guid.m_guidPtr->Set(buf.readPackGUID()); + uint64 value = buf.readPackGUID(); + ObjectGuid::ClampPlayerGuid(value); + guid.m_guidPtr->Set(value); return buf; } +// If the GUID is a player GUID, clamp it to the low guid or we open +// ourselves to packet manipulation where a player can send their low +// guid with a mutple of 0xFFFFFFFF+1 added to it, causing hashing to +// fail but some other functionality to succeed +void ObjectGuid::ClampPlayerGuid(uint64& value) +{ + if (ObjectGuid::GetHigh(value) == HIGHGUID_PLAYER) + { + value = static_cast(GetCounter(value, HasEntry(HIGHGUID_PLAYER))); + } +} + template class ObjectGuidGenerator; template class ObjectGuidGenerator; template class ObjectGuidGenerator; diff --git a/src/game/ObjectGuid.h b/src/game/ObjectGuid.h index ee0b83474..8f79a44e0 100644 --- a/src/game/ObjectGuid.h +++ b/src/game/ObjectGuid.h @@ -141,19 +141,26 @@ class MANGOS_DLL_SPEC ObjectGuid public: // modifiers PackedGuidReader ReadAsPacked() { return PackedGuidReader(*this); } - void Set(uint64 const& guid) { m_guid = guid; } + void Set(uint64 const& guid); void Clear() { m_guid = 0; } PackedGuid WriteAsPacked() const; public: // accessors uint64 const& GetRawValue() const { return m_guid; } - HighGuid GetHigh() const { return HighGuid((m_guid >> 48) & 0x0000FFFF); } + static HighGuid GetHigh(uint64 guid) { return HighGuid((guid >> 48) & 0x0000FFFF); } + static void ClampPlayerGuid(uint64& value); + HighGuid GetHigh() const { return GetHigh(m_guid); } uint32 GetEntry() const { return HasEntry() ? uint32((m_guid >> 24) & UI64LIT(0x0000000000FFFFFF)) : 0; } uint32 GetCounter() const { - return HasEntry() - ? uint32(m_guid & UI64LIT(0x0000000000FFFFFF)) - : uint32(m_guid & UI64LIT(0x00000000FFFFFFFF)); + return GetCounter(m_guid, HasEntry()); + } + + static uint32 GetCounter(uint64 guid, bool hasEntry) + { + return hasEntry + ? uint32(guid & UI64LIT(0x0000000000FFFFFF)) + : uint32(guid & UI64LIT(0x00000000FFFFFFFF)); } static uint32 GetMaxCounter(HighGuid high)