Enforce limits in player settings packet to prevent possible crash

This commit is contained in:
MysterD 2022-03-04 21:33:29 -08:00
parent a924f7977b
commit 1fcf776e34
5 changed files with 10 additions and 4 deletions

View file

@ -4,6 +4,8 @@
#include "types.h" #include "types.h"
// NOTE: do not include any additional headers // NOTE: do not include any additional headers
#define PALETTE_MAX 24
enum CharacterType { enum CharacterType {
CT_MARIO, CT_MARIO,
CT_LUIGI, CT_LUIGI,

View file

@ -85,7 +85,7 @@ struct GraphNodeObject gMirrorMario[MAX_PLAYERS]; // copy of Mario's geo node f
gdSPDefLights1((pr >> 1), (pg >> 1), (pb >> 1), pr, pg, pb, 0x28, 0x28, 0x28), \ gdSPDefLights1((pr >> 1), (pg >> 1), (pb >> 1), pr, pg, pb, 0x28, 0x28, 0x28), \
} }
struct PlayerColor gPlayerColors[] = { struct PlayerColor gPlayerColors[PALETTE_MAX] = {
// default mario // default mario
DEFINE_PLAYER_COLOR(0xff, 0x00, 0x00, /**/ 0x00, 0x00, 0xff), DEFINE_PLAYER_COLOR(0xff, 0x00, 0x00, /**/ 0x00, 0x00, 0xff),
// default luigi // default luigi

View file

@ -91,7 +91,7 @@ void djui_panel_player_create(struct DjuiBase* caller) {
djui_base_set_size(&selectionbox1->base, 1.0f, 32); djui_base_set_size(&selectionbox1->base, 1.0f, 32);
djui_interactable_hook_value_change(&selectionbox1->base, djui_panel_player_value_changed); djui_interactable_hook_value_change(&selectionbox1->base, djui_panel_player_value_changed);
char* paletteChoices[24] = { char* paletteChoices[PALETTE_MAX] = {
"Mario", "Mario",
"Luigi", "Luigi",
"Waluigi", "Waluigi",
@ -117,7 +117,7 @@ void djui_panel_player_create(struct DjuiBase* caller) {
"Fire Waluigi", "Fire Waluigi",
"Fire Wario", "Fire Wario",
}; };
struct DjuiSelectionbox* selectionbox2 = djui_selectionbox_create(&body->base, "Palette", paletteChoices, 24, &configPlayerPalette); struct DjuiSelectionbox* selectionbox2 = djui_selectionbox_create(&body->base, "Palette", paletteChoices, PALETTE_MAX, &configPlayerPalette);
djui_base_set_size_type(&selectionbox2->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); djui_base_set_size_type(&selectionbox2->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&selectionbox2->base, 1.0f, 32); djui_base_set_size(&selectionbox2->base, 1.0f, 32);
djui_interactable_hook_value_change(&selectionbox2->base, djui_panel_player_value_changed); djui_interactable_hook_value_change(&selectionbox2->base, djui_panel_player_value_changed);

View file

@ -42,6 +42,10 @@ void network_receive_player_settings(struct Packet* p) {
return; return;
} }
// sanity check
if (playerModel >= CT_MAX) { playerModel = CT_MARIO; }
if (playerPalette >= PALETTE_MAX) { playerPalette = 0; }
struct NetworkPlayer* np = network_player_from_global_index(globalId); struct NetworkPlayer* np = network_player_from_global_index(globalId);
snprintf(np->name, MAX_PLAYER_STRING, "%s", playerName); snprintf(np->name, MAX_PLAYER_STRING, "%s", playerName);
np->modelIndex = playerModel; np->modelIndex = playerModel;

View file

@ -224,7 +224,7 @@ void main_func(void) {
mod_list_init(); mod_list_init();
configfile_load(configfile_name()); configfile_load(configfile_name());
if (configPlayerModel >= CT_MAX) { configPlayerModel = 0; } if (configPlayerModel >= CT_MAX) { configPlayerModel = 0; }
if (configPlayerPalette >= 24) { configPlayerPalette = 0; } if (configPlayerPalette >= PALETTE_MAX) { configPlayerPalette = 0; }
if (gCLIOpts.FullScreen == 1) if (gCLIOpts.FullScreen == 1)
configWindow.fullscreen = true; configWindow.fullscreen = true;