From 0e74b5f55b6cbac79ddbf55e6e1896e33102267b Mon Sep 17 00:00:00 2001 From: Vincent Stumpf Date: Wed, 20 Sep 2017 11:33:25 -0700 Subject: [PATCH] Fixed potential crash in pc_bonus (#2423) * Fixes #2420. * If a bonus script command is used in an NPC with a non-existent bonus type, the server crashes. Thanks to @vstumpf and @anacondaqq! --- src/map/pc.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/map/pc.c b/src/map/pc.c index 4682102bb3..409a02622a 100755 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -3129,9 +3129,12 @@ void pc_bonus(struct map_session_data *sd,int type,int val) else if (current_equip_combo_pos > 0) { ShowWarning("pc_bonus: unknown bonus type %d %d in a combo with item #%d\n", type, val, sd->inventory_data[pc_checkequip( sd, current_equip_combo_pos )]->nameid); } - else { + else if (current_equip_card_id > 0 || current_equip_item_index > 0) { ShowWarning("pc_bonus: unknown bonus type %d %d in item #%d\n", type, val, current_equip_card_id ? current_equip_card_id : sd->inventory_data[current_equip_item_index]->nameid); } + else { + ShowWarning("pc_bonus: unknown bonus type %d %d in unknown usage. Report this!\n", type, val); + } break; } } @@ -3810,9 +3813,12 @@ void pc_bonus2(struct map_session_data *sd,int type,int type2,int val) } else if (current_equip_combo_pos > 0) { ShowWarning("pc_bonus2: unknown bonus type %d %d %d in a combo with item #%d\n", type, type2, val, sd->inventory_data[pc_checkequip( sd, current_equip_combo_pos )]->nameid); + } + else if (current_equip_card_id > 0 || current_equip_item_index > 0) { + ShowWarning("pc_bonus2: unknown bonus type %d %d %d in item #%d\n", type, type2, val, current_equip_card_id ? current_equip_card_id : sd->inventory_data[current_equip_item_index]->nameid); } else { - ShowWarning("pc_bonus2: unknown bonus type %d %d %d in item #%d\n", type, type2, val, current_equip_card_id ? current_equip_card_id : sd->inventory_data[current_equip_item_index]->nameid); + ShowWarning("pc_bonus2: unknown bonus type %d %d %d in unknown usage. Report this!\n", type, type2, val); } break; } @@ -3934,9 +3940,12 @@ void pc_bonus3(struct map_session_data *sd,int type,int type2,int type3,int val) else if (current_equip_combo_pos > 0) { ShowWarning("pc_bonus3: unknown bonus type %d %d %d %d in a combo with item #%d\n", type, type2, type3, val, sd->inventory_data[pc_checkequip( sd, current_equip_combo_pos )]->nameid); } - else { + else if (current_equip_card_id > 0 || current_equip_item_index > 0) { ShowWarning("pc_bonus3: unknown bonus type %d %d %d %d in item #%d\n", type, type2, type3, val, current_equip_card_id ? current_equip_card_id : sd->inventory_data[current_equip_item_index]->nameid); } + else { + ShowWarning("pc_bonus3: unknown bonus type %d %d %d %d in unknown usage. Report this!\n", type, type2, type3, val); + } break; } } @@ -4017,9 +4026,12 @@ void pc_bonus4(struct map_session_data *sd,int type,int type2,int type3,int type else if (current_equip_combo_pos > 0) { ShowWarning("pc_bonus4: unknown bonus type %d %d %d %d %d in a combo with item #%d\n", type, type2, type3, type4, val, sd->inventory_data[pc_checkequip( sd, current_equip_combo_pos )]->nameid); } - else { + else if (current_equip_card_id > 0 || current_equip_item_index > 0) { ShowWarning("pc_bonus4: unknown bonus type %d %d %d %d %d in item #%d\n", type, type2, type3, type4, val, current_equip_card_id ? current_equip_card_id : sd->inventory_data[current_equip_item_index]->nameid); } + else { + ShowWarning("pc_bonus4: unknown bonus type %d %d %d %d %d in unknown usage. Report this!\n", type, type2, type3, type4, val); + } break; } } @@ -4066,9 +4078,12 @@ void pc_bonus5(struct map_session_data *sd,int type,int type2,int type3,int type else if (current_equip_combo_pos > 0) { ShowWarning("pc_bonus5: unknown bonus type %d %d %d %d %d %d in a combo with item #%d\n", type, type2, type3, type4, type5, val, sd->inventory_data[pc_checkequip( sd, current_equip_combo_pos )]->nameid); } - else { + else if (current_equip_card_id > 0 || current_equip_item_index > 0) { ShowWarning("pc_bonus5: unknown bonus type %d %d %d %d %d %d in item #%d\n", type, type2, type3, type4, type5, val, current_equip_card_id ? current_equip_card_id : sd->inventory_data[current_equip_item_index]->nameid); } + else { + ShowWarning("pc_bonus5: unknown bonus type %d %d %d %d %d %d in unknown usage. Report this!\n", type, type2, type3, type4, type5, val); + } break; } }