From 0098b0c4724acae4f3adc49c0ea01b41c4e1a9e5 Mon Sep 17 00:00:00 2001 From: MysterD Date: Thu, 10 Feb 2022 18:05:47 -0800 Subject: [PATCH] Fixed crashes on 32-bit due to pointer offsets --- src/pc/network/packets/packet_join.c | 4 ++-- .../network/packets/packet_level_respawn_info.c | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/pc/network/packets/packet_join.c b/src/pc/network/packets/packet_join.c index dbf784f4..e8ead887 100644 --- a/src/pc/network/packets/packet_join.c +++ b/src/pc/network/packets/packet_join.c @@ -114,8 +114,8 @@ void network_send_join(struct Packet* joinRequestPacket) { char nullchar = '\0'; while (node != NULL && node->string != NULL) { int length = strlen(node->string); - packet_write(&p, node->string, sizeof(char) * length); - packet_write(&p, &nullchar, sizeof(char)); + packet_write(&p, node->string, sizeof(u8) * length); + packet_write(&p, &nullchar, sizeof(u8)); LOG_INFO("sending registered mod: %s", node->string); node = node->next; } diff --git a/src/pc/network/packets/packet_level_respawn_info.c b/src/pc/network/packets/packet_level_respawn_info.c index 8a9e596b..c1af4a62 100644 --- a/src/pc/network/packets/packet_level_respawn_info.c +++ b/src/pc/network/packets/packet_level_respawn_info.c @@ -23,18 +23,18 @@ static s16* get_respawn_info_from_macro_offset(u16 areaIndex, u16 macroOffset) { // loop through macro objects for santiziation - u16 maxOffset = 0; + u16 index = 0; s16* macroObjList = gAreaData[areaIndex].macroObjects; while (macroObjList != NULL && *macroObjList != -1) { macroObjList += 4; s16* respawnInfo = macroObjList++; - maxOffset = respawnInfo - gAreaData[areaIndex].macroObjects; + if (macroOffset == index) { + return respawnInfo; + } + index++; } - // sanitize array - if (macroOffset > maxOffset) { return NULL; } - - return gAreaData[areaIndex].macroObjects + macroOffset; + return NULL; } static u32* get_respawn_info_from_spawn_info_index(u16 areaIndex, u16 fromSpawnInfoIndex) { @@ -56,6 +56,7 @@ static u32* get_respawn_info_from_spawn_info_index(u16 areaIndex, u16 fromSpawnI static u16 get_macro_offset_of_object(struct Object* o) { // loop through macro objects to find object s16* macroObjList = gCurrentArea->macroObjects; + u16 index = 0; while (macroObjList != NULL && *macroObjList != -1) { // grab preset ID s32 presetID = (*macroObjList & 0x1FF) - 31; // Preset identifier for MacroObjectPresets array @@ -66,8 +67,9 @@ static u16 get_macro_offset_of_object(struct Object* o) { s16* respawnInfo = macroObjList++; if (o->respawnInfo == respawnInfo) { - return (respawnInfo - gCurrentArea->macroObjects); + return index; } + index++; } return ERR_COULD_NOT_FIND_OBJECT;