Skip to content

Commit

Permalink
report (and secure) weaponinfo[] overruns (#1221)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiangreffrath authored Oct 17, 2023
1 parent 3741b89 commit a6f4274
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/d_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// atkstate, i.e. attack/fire/hit frame
// flashstate, muzzle flash
//
weaponinfo_t weaponinfo[NUMWEAPONS] =
weaponinfo_t weaponinfo[NUMWEAPONS+1] =
{
{
// fist
Expand Down Expand Up @@ -142,6 +142,9 @@ weaponinfo_t weaponinfo[NUMWEAPONS] =
0,
WPF_NOFLAG
},
{
0
},
};

//----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/d_items.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ typedef struct
int flags;
} weaponinfo_t;

extern weaponinfo_t weaponinfo[NUMWEAPONS];
extern weaponinfo_t weaponinfo[NUMWEAPONS+1];

#endif

Expand Down
7 changes: 7 additions & 0 deletions src/p_pspr.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//-----------------------------------------------------------------------------

#include "doomstat.h"
#include "i_printf.h"
#include "r_main.h"
#include "p_map.h"
#include "p_inter.h"
Expand Down Expand Up @@ -154,6 +155,12 @@ static void P_BringUpWeapon(player_t *player)
if (player->pendingweapon == wp_chainsaw)
S_StartSound(player->mo, sfx_sawup);

if (player->pendingweapon >= NUMWEAPONS)
{
player->pendingweapon = NUMWEAPONS;
I_Printf(VB_WARNING, "P_BringUpWeapon: weaponinfo overrun has occurred.");
}

newstate = weaponinfo[player->pendingweapon].upstate;

player->pendingweapon = wp_nochange;
Expand Down

0 comments on commit a6f4274

Please sign in to comment.