ValveSoftware / halflife

Half-Life 1 engine based games
Other
3.68k stars 623 forks source link

[Opposing Force] Game crash when colliding with spore nade if the owner of the entity is NULL #3056

Open hobokenn opened 3 years ago

hobokenn commented 3 years ago

How to reproduce: you need to gib a shock trooper after a nade throw, then save/load and catch the nade. I found the best place to do that is in the boss fight map, you can bait their nades easily by stepping back from the railing or just generally taking cover somewhere.

SamVanheer commented 3 years ago

This happens because the player's TakeDamage method is called with a null attacker.

When this line: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/player.cpp#L471

is executed it tries to access pevAttacker->pContainingEntity: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/cbase.h#L267 https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/util.h#L109

Since the attacker is null this crashes the program.

CBaseEntity::Instance has a failsafe that returns the world if the given entity is null, but this only works if the overload that takes an edict_t* is called directly. Since this calls the entvars_t* overload it crashes. A foolproof fix should apply the same failsafe to all overloads that could be given a null pointer:

static CBaseEntity *Instance( entvars_t *pev )
{
    if (!pev)
        return Instance(ENT(0));

    return Instance(ENT(pev));
}