Skip to content
Permalink
Browse files

Fixed potential race-condition possibility in cart item transaction (#…

…4139)



Co-authored-by: Cydh Ramdh <cydh@users.noreply.github.com>
Co-Authored-By: Aleos <aleos89@users.noreply.github.com>
  • Loading branch information...
3 people committed May 2, 2019
1 parent 1832fdf commit 7f772c32d3be201861946bb64720c231828465ac
Showing with 13 additions and 9 deletions.
  1. +13 −9 src/map/pc.cpp
@@ -5447,7 +5447,7 @@ void pc_putitemtocart(struct map_session_data *sd,int idx,int amount)

item_data = &sd->inventory.u.items_inventory[idx];

if( item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending )
if( item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending || sd->state.prevend )
return;

if( item_data->equipSwitch ){
@@ -5487,21 +5487,25 @@ int pc_cartitem_amount(struct map_session_data* sd, int idx, int amount)
*------------------------------------------*/
void pc_getitemfromcart(struct map_session_data *sd,int idx,int amount)
{
struct item *item_data;
unsigned char flag = 0;

nullpo_retv(sd);

if (idx < 0 || idx >= MAX_CART) //Invalid index check [Skotlex]
return;

item_data=&sd->cart.u.items_cart[idx];
item* item_data=&sd->cart.u.items_cart[idx];

if(item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending )
if (item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending || sd->state.prevend)
return;
if((flag = pc_additem(sd,item_data,amount,LOG_TYPE_NONE)) == 0)
pc_cart_delitem(sd,idx,amount,0,LOG_TYPE_NONE);
else {

if (pc_checkadditem(sd, item_data->nameid, amount) == CHKADDITEM_OVERAMOUNT) {
return;
}

item item_copy = *item_data;

pc_cart_delitem(sd, idx, amount, 0, LOG_TYPE_NONE);
char flag = pc_additem(sd, &item_copy, amount, LOG_TYPE_NONE);
if(flag != ADDITEM_SUCCESS) {
clif_dropitem(sd,idx,0);
clif_additem(sd,0,0,flag);
}

4 comments on commit 7f772c3

@schickrazor

This comment has been minimized.

Copy link

replied May 7, 2019

Hi! I applied this patch in my rA 72c129ba and this happens:

  • 15000 Acid Bottles are in the Cart
  • Charatcter is overweight (90%)
  • I get 5000 Acid Bottles from Cart to Inventory
  • After that, the acid bottles are gone and there is a message "You cannot carry more items because you are overweight"
@schickrazor

This comment has been minimized.

Copy link

replied May 7, 2019

Character is overweigt at 90%
image

I get 5000 Acid bottles and gone
image

@anacondaq

This comment has been minimized.

Copy link

replied May 7, 2019

@schickrazor revert back the patch, and just apply a part sd->state.prevend to if() conditions above from the patch. It will help. Everything else not really needed.

@schickrazor

This comment has been minimized.

Copy link

replied May 7, 2019

It worked. Thank you.

Please sign in to comment.
You can’t perform that action at this time.