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:
hondacrx
2024-03-12 22:16:39 -04:00
parent 7e7b8ed58b
commit 5b938c1a3e
2 changed files with 41 additions and 36 deletions
+12 -7
View File
@@ -785,20 +785,25 @@ namespace Game
{
SendAuctionExpired(auction, trans);
Global.ScriptMgr.OnAuctionExpire(this, auction);
RemoveAuction(trans, auction);
}
///- Or perform the transaction
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 send the item to the winner
//we send the money to the seller
SendAuctionWon(auction, null, trans);
SendAuctionSold(auction, null, trans);
SendAuctionSold(copy, null, trans);
SendAuctionWon(copy, null, trans);
Global.ScriptMgr.OnAuctionSuccessful(this, auction);
}
///- In any case clear the auction
RemoveAuction(trans, auction);
}
// Run DB changes
@@ -1294,7 +1299,7 @@ namespace Game
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()} " +
$"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);
@@ -1393,7 +1398,7 @@ namespace Game
// data for gm.log
string bidderName = "";
bool logGmTrade= auction.ServerFlags.HasFlag(AuctionPostingServerFlag.GmLogBuyer);
bool logGmTrade = auction.ServerFlags.HasFlag(AuctionPostingServerFlag.GmLogBuyer);
if (bidder != null)
{
+1 -1
View File
@@ -390,8 +390,8 @@ namespace Game
if (canBuyout && placeBid.BidAmount == auction.BuyoutOrUnitPrice)
{
// buyout
auctionHouse.SendAuctionWon(auction, player, trans);
auctionHouse.SendAuctionSold(auction, null, trans);
auctionHouse.SendAuctionWon(auction, player, trans);
auctionHouse.RemoveAuction(trans, auction);
}