report (and secure) weaponinfo[] overruns (#1221)

This commit is contained in:
Fabian Greffrath 2023-10-17 08:21:42 +02:00 committed by GitHub
parent 3741b89a0d
commit a6f4274553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -32,7 +32,7 @@
// atkstate, i.e. attack/fire/hit frame
// flashstate, muzzle flash
//
weaponinfo_t weaponinfo[NUMWEAPONS] =
weaponinfo_t weaponinfo[NUMWEAPONS+1] =
{
{
// fist
@ -142,6 +142,9 @@ weaponinfo_t weaponinfo[NUMWEAPONS] =
0,
WPF_NOFLAG
},
{
0
},
};
//----------------------------------------------------------------------------

View File

@ -59,7 +59,7 @@ typedef struct
int flags;
} weaponinfo_t;
extern weaponinfo_t weaponinfo[NUMWEAPONS];
extern weaponinfo_t weaponinfo[NUMWEAPONS+1];
#endif

View File

@ -19,6 +19,7 @@
//-----------------------------------------------------------------------------
#include "doomstat.h"
#include "i_printf.h"
#include "r_main.h"
#include "p_map.h"
#include "p_inter.h"
@ -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;