Skip to content

Commit

Permalink
Fixed a server crash: #86
Browse files Browse the repository at this point in the history
Under the right conditions - cooperative game, friendly fire disabled through dmflags - a soldier accidentally shooting a corpse (misc_deadsoldier) caused that corpse to try and fight back. But corpses don't have any AI functions assigned, so that caused the server to execute code at null address.

More technically, the T_Damage function is called with targ=dead and attacker=monster. The "friendly fire avoidance" code sets damage=0. Then the "do the damage" code is skipped because of that, and the function continues to execute assuming that the target is alive, and calls M_ReactToDamage on it. That function calls FoundTarget and HuntTarget, and the latter crashes.

I'm not entirely certain that this is the right way to fix this, or skipping the call to T_Damage on zero damage would be better. That would prevent pointless monster infights in no-friendly-fire mode. Or is it better to still allow monster infights when friendly fire is disabled?
  • Loading branch information
apanteleev committed Oct 10, 2020
1 parent 5c6ff0c commit 4132eed
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/baseq2/g_combat.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ void M_ReactToDamage(edict_t *targ, edict_t *attacker)
if (attacker == targ || attacker == targ->enemy)
return;

// dead monsters, like misc_deadsoldier, don't have AI functions, but
// M_ReactToDamage might still be called on them
if (targ->svflags & SVF_DEADMONSTER)
return;

// if we are a good guy monster and our attacker is a player
// or another good guy, do not get mad at them
if (targ->monsterinfo.aiflags & AI_GOOD_GUY) {
Expand Down

0 comments on commit 4132eed

Please sign in to comment.