[8378] Use exceptions instead of explicit size checking for each packet

CHECK_PACKET_SIZE was pretty error prone; once it was forgotten mangosd
could crash due to the asserts in ByteBuffer.h. That was exploitable by
malicious players.
Furthermore, there were duplicate checks: Additionally to
CHECK_PACKET_SIZE, the ByteBuffer assertions keept an eye
on not exceeding the packet boundaries - just to crash the server for
sure in such a case.
To prevent memory leaks or other undesirable states, please read in
every handler all variables _before_ doing any concrete handling.
This commit is contained in:
arrai 2009-08-15 22:06:35 +02:00
parent c26c7395a1
commit a24f39a36f
32 changed files with 129 additions and 741 deletions

View file

@ -33,8 +33,6 @@
//void called when player click on auctioneer npc
void WorldSession::HandleAuctionHelloOpcode( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,8);
uint64 guid; //NPC guid
recv_data >> guid;
@ -151,8 +149,6 @@ void WorldSession::SendAuctionCancelledToBidderMail( AuctionEntry* auction )
//this void creates new auction and adds auction to some auctionhouse
void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,8+8+4+4+4);
uint64 auctioneer, item;
uint32 etime, bid, buyout;
recv_data >> auctioneer >> item;
@ -275,8 +271,6 @@ void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
//this function is called when client bids or buys out auction
void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,8+4+4);
uint64 auctioneer;
uint32 auctionId;
uint32 price;
@ -404,8 +398,6 @@ void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data )
//this void is called when auction_owner cancels his auction
void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,8+4);
uint64 auctioneer;
uint32 auctionId;
recv_data >> auctioneer;
@ -482,8 +474,6 @@ void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data )
//called when player lists his bids
void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,8+4+4);
uint64 guid; //NPC guid
uint32 listfrom; //page of auctions
uint32 outbiddedCount; //count of outbidded auctions
@ -538,8 +528,6 @@ void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data )
//this void sends player info about his auctions
void WorldSession::HandleAuctionListOwnerItems( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,8+4);
uint32 listfrom;
uint64 guid;
@ -575,8 +563,6 @@ void WorldSession::HandleAuctionListOwnerItems( WorldPacket & recv_data )
//this void is called when player clicks on search button
void WorldSession::HandleAuctionListItems( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data,8+4+1+1+1+4+4+4+4+1);
std::string searchedname;
uint8 levelmin, levelmax, usable;
uint32 listfrom, auctionSlotID, auctionMainCategory, auctionSubCategory, quality;
@ -586,9 +572,6 @@ void WorldSession::HandleAuctionListItems( WorldPacket & recv_data )
recv_data >> listfrom; // start, used for page control listing by 50 elements
recv_data >> searchedname;
// recheck with known string size
CHECK_PACKET_SIZE(recv_data,8+4+(searchedname.size()+1)+1+1+4+4+4+4+1);
recv_data >> levelmin >> levelmax;
recv_data >> auctionSlotID >> auctionMainCategory >> auctionSubCategory;
recv_data >> quality >> usable;