diff options
author | megamage <none@none.none> | 2011-09-28 16:03:46 -0400 |
---|---|---|
committer | megamage <none@none.none> | 2011-09-28 16:03:46 -0400 |
commit | 2730d51266af40ce07c26d2282c111558ea5e14c (patch) | |
tree | c2bfbb821d33adfdc34c1991fe9ce412d38e52ec /src | |
parent | 8dd88fa43c04efba64661763452aaabf1da3af43 (diff) |
Fix possible total price overflow when buying items. Fix #3137.
Thanks to BroodWyrm for finding out the problem.
Diffstat (limited to 'src')
-rwxr-xr-x | src/server/game/Entities/Player/Player.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 9b4b8b8251e..4635c8a1aef 100755 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -20521,16 +20521,25 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 } } - uint32 price = crItem->IsGoldRequired(pProto) ? pProto->BuyPrice * count : 0; + uint32 price = 0; + if(crItem->IsGoldRequired(pProto)) + { + uint32 maxCount = 0xFFFFFFFF / pProto->BuyPrice; //why price is int32? can be negative? + if((uint32)count > maxCount) + { + sLog->outError("Player %s tried to buy %u item id %u, causing overflow", GetName(), (uint32)count, pProto->ItemId); + count = (uint8)maxCount; + } + price = pProto->BuyPrice * count; //it should not exceed 0xFFFFFFFF - // reputation discount - if (price) + // reputation discount price = uint32(floor(price * GetReputationPriceDiscount(pCreature))); - if (!HasEnoughMoney(price)) - { - SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, pCreature, item, 0); - return false; + if (!HasEnoughMoney(price)) + { + SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, pCreature, item, 0); + return false; + } } if ((bag == NULL_BAG && slot == NULL_SLOT) || IsInventoryPos(bag, slot)) |