From 988c75d6215eed87608686dde2e523d4a538da59 Mon Sep 17 00:00:00 2001 From: MysterD Date: Sun, 13 Feb 2022 16:31:22 -0800 Subject: [PATCH] Fixed crash in save set flag packet --- src/pc/network/packets/packet_save_set_flag.c | 11 +++++++++++ src/pc/network/packets/packet_spawn_objects.c | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pc/network/packets/packet_save_set_flag.c b/src/pc/network/packets/packet_save_set_flag.c index e135833a..2384cf7a 100644 --- a/src/pc/network/packets/packet_save_set_flag.c +++ b/src/pc/network/packets/packet_save_set_flag.c @@ -2,6 +2,7 @@ #include "../network.h" #include "game/save_file.h" #include "buffers/buffers.h" +#include "pc/debuglog.h" void network_send_save_set_flag(s32 fileIndex, s32 courseIndex, u8 courseStars, u32 flags) { struct Packet p = { 0 }; @@ -23,6 +24,16 @@ void network_receive_save_set_flag(struct Packet* p) { packet_read(p, &courseStars, sizeof(u8)); packet_read(p, &flags, sizeof(u32)); + if (fileIndex >= NUM_SAVE_FILES) { + LOG_ERROR("Invalid fileIndex: %d", fileIndex); + return; + } + + if (courseIndex >= COURSE_COUNT) { + LOG_ERROR("Invalid courseIndex: %d", courseIndex); + return; + } + gSaveBuffer.files[fileIndex][0].courseStars[courseIndex] |= courseStars; gSaveBuffer.files[fileIndex][0].flags |= flags; gSaveFileModified = TRUE; diff --git a/src/pc/network/packets/packet_spawn_objects.c b/src/pc/network/packets/packet_spawn_objects.c index 064594b4..578f13f6 100644 --- a/src/pc/network/packets/packet_spawn_objects.c +++ b/src/pc/network/packets/packet_spawn_objects.c @@ -113,7 +113,8 @@ void network_receive_spawn_objects(struct Packet* p) { parentObj = gMarioStates[0].marioObj; } else { // sanity check parent id - if (i == 0 && data.parentId >= MAX_SYNC_OBJECTS) { + u32 maxSyncObjects = MAX_SYNC_OBJECTS; + if (i == 0 && data.parentId >= maxSyncObjects) { LOG_ERROR("Invalid spawn object parentId: %u", data.parentId); return; }