aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShocker <shocker@freakz.ro>2011-10-07 09:54:37 -0700
committerShocker <shocker@freakz.ro>2011-10-07 09:54:37 -0700
commita3c46d70237194a08b60440a7ccc18f7e5250d7f (patch)
tree7717d09c0d2a927fbd870b46fa1d03c9fba519a3 /src
parent88277ac10ce41eb91e0065306b4df5a2b9e2a433 (diff)
parent42d1562183dd0598de155e30264393edc6925a21 (diff)
Merge pull request #3393 from megamage/master
Fix possible total price overflow when buying items. Fix #3137.
Diffstat (limited to 'src')
-rw-r--r--[-rwxr-xr-x]src/server/game/Entities/Player/Player.cpp23
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 0076d58b4e8..161563b1127 100755..100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -20515,16 +20515,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) && pProto->BuyPrice > 0) //Assume price cannot be negative (do not know why it is int32)
+ {
+ uint32 maxCount = MAX_MONEY_AMOUNT / pProto->BuyPrice;
+ 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 MAX_MONEY_AMOUNT
- // reputation discount
- if (price)
+ // reputation discount
price = uint32(floor(price * GetReputationPriceDiscount(creature)));
- if (!HasEnoughMoney(price))
- {
- SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, creature, item, 0);
- return false;
+ if (!HasEnoughMoney(price))
+ {
+ SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, creature, item, 0);
+ return false;
+ }
}
if ((bag == NULL_BAG && slot == NULL_SLOT) || IsInventoryPos(bag, slot))