Skip to content

Commit 185fec5

Browse files
authored
fix: use-after-free in CStateMonsterAttackOnRun::update_aim_side (#1973)
1 parent c4d40bc commit 185fec5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/xrGame/ai/monsters/states/monster_state_attack_on_run.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CStateMonsterAttackOnRun : public CState<_Object>
1717
virtual void execute();
1818
virtual void finalize();
1919
virtual void critical_finalize();
20-
virtual void remove_links(IGameObject* object) { inherited::remove_links(object); }
20+
virtual void remove_links(IGameObject* object);
2121
virtual bool check_completion();
2222
virtual bool check_start_conditions();
2323

src/xrGame/ai/monsters/states/monster_state_attack_on_run_inline.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void ATTACK_ON_RUN_STATE::initialize()
5454
m_is_jumping = this->object->is_jumping();
5555
m_reach_old_target = false;
5656
m_attack_side_chosen_time = 0;
57+
m_enemy_to_attack = nullptr;
5758

5859
choose_next_atack_animation();
5960
}
@@ -179,6 +180,9 @@ void ATTACK_ON_RUN_STATE::update_aim_side()
179180
{
180181
CEntityAlive const* const enemy = m_attacking ? m_enemy_to_attack : this->object->EnemyMan.get_enemy();
181182

183+
if (!enemy)
184+
return;
185+
182186
Fvector const self_dir = this->object->Direction();
183187
Fvector const self_to_enemy = enemy->Position() - this->object->Position();
184188

@@ -621,6 +625,15 @@ bool ATTACK_ON_RUN_STATE::check_completion()
621625
return false;
622626
}
623627

628+
TEMPLATE_SIGNATURE
629+
void ATTACK_ON_RUN_STATE::remove_links(IGameObject* object)
630+
{
631+
inherited::remove_links(object);
632+
633+
if (m_enemy_to_attack == object)
634+
m_enemy_to_attack = nullptr;
635+
}
636+
624637
#undef DEBUG_STATE
625638

626639
#undef TEMPLATE_SIGNATURE

0 commit comments

Comments
 (0)