From 4be4293278e3917df526f9f3e9594e3090e10aac Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 30 Sep 2022 03:11:14 +0300 Subject: [PATCH 27/27] Fix action_decision_maybe_auto() NULL dereferences See osdn #45729 Signed-off-by: Marko Lindqvist --- client/packhand.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/client/packhand.c b/client/packhand.c index ca5ec58fa4..10abb489a2 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -4938,7 +4938,7 @@ static void action_decision_maybe_auto(struct unit *actor_unit, { action_id auto_action; - fc_assert_ret(actor_unit); + fc_assert_ret(actor_unit != NULL); auto_action = auto_attack_act(act_probs); @@ -4954,19 +4954,25 @@ static void action_decision_maybe_auto(struct unit *actor_unit, case ATK_TILE: case ATK_UNITS: case ATK_EXTRAS: - request_do_action(auto_action, - actor_unit->id, tile_index(target_tile), - 0, ""); + if (target_tile != NULL) { + request_do_action(auto_action, + actor_unit->id, tile_index(target_tile), + 0, ""); + } break; case ATK_CITY: - request_do_action(auto_action, - actor_unit->id, target_city->id, - 0, ""); + if (target_city != NULL) { + request_do_action(auto_action, + actor_unit->id, target_city->id, + 0, ""); + } break; case ATK_UNIT: - request_do_action(auto_action, - actor_unit->id, target_unit->id, - 0, ""); + if (target_unit != NULL) { + request_do_action(auto_action, + actor_unit->id, target_unit->id, + 0, ""); + } break; case ATK_SELF: request_do_action(auto_action, @@ -5048,8 +5054,10 @@ void handle_unit_actions(const struct packet_unit_actions *packet) } break; case REQEST_BACKGROUND_FAST_AUTO_ATTACK: - action_decision_maybe_auto(actor_unit, act_probs, - target_unit, target_city, target_tile); + if (actor_unit != NULL) { + action_decision_maybe_auto(actor_unit, act_probs, + target_unit, target_city, target_tile); + } break; default: log_warn("Unknown request_kind %d in reply", request_kind); -- 2.35.1