Core/AuctionHouse: Fixed possible use after free when auctions are removed with offline buyers
Port From (https://github.com/TrinityCore/TrinityCore/commit/1f73cf9f19679f5b888f9df475b94c9405f2d746)
This commit is contained in:
@@ -785,20 +785,25 @@ namespace Game
|
|||||||
{
|
{
|
||||||
SendAuctionExpired(auction, trans);
|
SendAuctionExpired(auction, trans);
|
||||||
Global.ScriptMgr.OnAuctionExpire(this, auction);
|
Global.ScriptMgr.OnAuctionExpire(this, auction);
|
||||||
|
|
||||||
|
RemoveAuction(trans, auction);
|
||||||
}
|
}
|
||||||
///- Or perform the transaction
|
///- Or perform the transaction
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Copy data before freeing AuctionPosting in auctionHouse->RemoveAuction
|
||||||
|
// Because auctionHouse->SendAuctionWon can unload items if bidder is offline
|
||||||
|
// we need to RemoveAuction before sending mails
|
||||||
|
AuctionPosting copy = auction;
|
||||||
|
RemoveAuction(trans, auction);
|
||||||
|
|
||||||
//we should send an "item sold" message if the seller is online
|
//we should send an "item sold" message if the seller is online
|
||||||
//we send the item to the winner
|
//we send the item to the winner
|
||||||
//we send the money to the seller
|
//we send the money to the seller
|
||||||
SendAuctionWon(auction, null, trans);
|
SendAuctionSold(copy, null, trans);
|
||||||
SendAuctionSold(auction, null, trans);
|
SendAuctionWon(copy, null, trans);
|
||||||
Global.ScriptMgr.OnAuctionSuccessful(this, auction);
|
Global.ScriptMgr.OnAuctionSuccessful(this, auction);
|
||||||
}
|
}
|
||||||
|
|
||||||
///- In any case clear the auction
|
|
||||||
RemoveAuction(trans, auction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run DB changes
|
// Run DB changes
|
||||||
@@ -1294,7 +1299,7 @@ namespace Game
|
|||||||
ownerName = Global.ObjectMgr.GetCypherString(CypherStrings.Unknown);
|
ownerName = Global.ObjectMgr.GetCypherString(CypherStrings.Unknown);
|
||||||
|
|
||||||
Log.outCommand(bidderAccId, $"GM {player.GetName()} (Account: {bidderAccId}) bought commodity in auction: {items[0].Items[0].GetName(Global.WorldMgr.GetDefaultDbcLocale())} (Entry: {items[0].Items[0].GetEntry()} " +
|
Log.outCommand(bidderAccId, $"GM {player.GetName()} (Account: {bidderAccId}) bought commodity in auction: {items[0].Items[0].GetName(Global.WorldMgr.GetDefaultDbcLocale())} (Entry: {items[0].Items[0].GetEntry()} " +
|
||||||
$"Count: {boughtFromAuction}) and pay money: { auction.BuyoutOrUnitPrice * boughtFromAuction}. Original owner {ownerName} (Account: {Global.CharacterCacheStorage.GetCharacterAccountIdByGuid(auction.Owner)})");
|
$"Count: {boughtFromAuction}) and pay money: {auction.BuyoutOrUnitPrice * boughtFromAuction}. Original owner {ownerName} (Account: {Global.CharacterCacheStorage.GetCharacterAccountIdByGuid(auction.Owner)})");
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong auctionHouseCut = CalculateAuctionHouseCut(auction.BuyoutOrUnitPrice * boughtFromAuction);
|
ulong auctionHouseCut = CalculateAuctionHouseCut(auction.BuyoutOrUnitPrice * boughtFromAuction);
|
||||||
@@ -1393,7 +1398,7 @@ namespace Game
|
|||||||
|
|
||||||
// data for gm.log
|
// data for gm.log
|
||||||
string bidderName = "";
|
string bidderName = "";
|
||||||
bool logGmTrade= auction.ServerFlags.HasFlag(AuctionPostingServerFlag.GmLogBuyer);
|
bool logGmTrade = auction.ServerFlags.HasFlag(AuctionPostingServerFlag.GmLogBuyer);
|
||||||
|
|
||||||
if (bidder != null)
|
if (bidder != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -390,8 +390,8 @@ namespace Game
|
|||||||
if (canBuyout && placeBid.BidAmount == auction.BuyoutOrUnitPrice)
|
if (canBuyout && placeBid.BidAmount == auction.BuyoutOrUnitPrice)
|
||||||
{
|
{
|
||||||
// buyout
|
// buyout
|
||||||
auctionHouse.SendAuctionWon(auction, player, trans);
|
|
||||||
auctionHouse.SendAuctionSold(auction, null, trans);
|
auctionHouse.SendAuctionSold(auction, null, trans);
|
||||||
|
auctionHouse.SendAuctionWon(auction, player, trans);
|
||||||
|
|
||||||
auctionHouse.RemoveAuction(trans, auction);
|
auctionHouse.RemoveAuction(trans, auction);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user