summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2024-07-31 21:51:00 -0600
committerGitHub <noreply@github.com>2024-07-31 21:51:00 -0600
commit48a8342f3fff5df04737cbd0511945a8bc5d6dd9 (patch)
treea0ace17d76f5eb68f87288551b64bcf2f1590baa /src
parentfee2dc308a2461041f685bf3b884c1b9382b755c (diff)
Fix Buffer Overflows (#28)
* Update code_800AF9B0.c * Update code_80005FD0.c * Update code_800029B0.c * Update code_80091750.c * Update code_80091750.h * Update code_80005FD0.c
Diffstat (limited to 'src')
-rw-r--r--src/code_800029B0.c2
-rw-r--r--src/code_80005FD0.c2
-rw-r--r--src/code_80091750.c47
-rw-r--r--src/code_80091750.h4
-rw-r--r--src/code_800AF9B0.c16
5 files changed, 38 insertions, 33 deletions
diff --git a/src/code_800029B0.c b/src/code_800029B0.c
index 74e43a3dc..a8be23efc 100644
--- a/src/code_800029B0.c
+++ b/src/code_800029B0.c
@@ -128,7 +128,7 @@ u16 D_8015F890;
u16 D_8015F892;
u16 D_8015F894;
// Indexed by Player ID. Track time in seconds since player has last crossed the finish line
-f32 gTimePlayerLastTouchedFinishLine[8];
+f32 gTimePlayerLastTouchedFinishLine[NUM_PLAYERS];
u8 *gNmiUnknown1;
u8 *gNmiUnknown2;
diff --git a/src/code_80005FD0.c b/src/code_80005FD0.c
index 3b3a2f057..4e5458530 100644
--- a/src/code_80005FD0.c
+++ b/src/code_80005FD0.c
@@ -103,7 +103,7 @@ u16 D_80163318[12];
u16 D_80163330[10];
u16 D_80163344[2];
u16 D_80163348[2];
-u16 D_8016334C[2];
+u16 D_8016334C[8]; // Increased from 2 to 8 to prevent array overflow.
u16 gSpeedKartAIBehaviour[12];
s32 D_80163368[4];
s32 D_80163378;
diff --git a/src/code_80091750.c b/src/code_80091750.c
index f738433f6..1d921504b 100644
--- a/src/code_80091750.c
+++ b/src/code_80091750.c
@@ -59,8 +59,7 @@ s8 D_8018D9D8;
s8 D_8018D9D9;
struct_8018D9E0_entry D_8018D9E0[D_8018D9E0_SIZE];
struct_8018DEE0_entry D_8018DEE0[D_8018DEE0_SIZE];
-struct_8018E060_entry D_8018E060[D_8018E060_SIZE];
-UNUSED u8 code_80091750_bss_padding0[8];
+struct_8018E060_entry D_8018E060[D_8018E060_SIZE + 1];
struct_8018E0E8_entry D_8018E0E8[D_8018E0E8_SIZE];
s32 gD_8018E118TotalSize;
struct_8018E118_entry D_8018E118[D_8018E118_SIZE];
@@ -1596,6 +1595,7 @@ void func_80092258(void) {
}
}
+//! @bug vtx overflow from idx + 36 in this func
void func_80092290(s32 arg0, s32 *arg1, s32 *arg2) {
s32 temp_v1;
s32 i;
@@ -10141,30 +10141,45 @@ escape:
* reasoning on the original author(s) part.
**/
struct_8018D9E0_entry *find_8018D9E0_entry_dupe(s32 arg0) {
- struct_8018D9E0_entry *entry = D_8018D9E0;
- for (; !(entry > (&D_8018D9E0[D_8018D9E0_SIZE])); entry++) {
- if (entry->type == arg0) {
- goto escape;
+ for (size_t i = 0; i < ARRAY_COUNT(D_8018D9E0); i++) {
+ if (&D_8018D9E0[i].type == arg0) {
+ return &D_8018D9E0[i];
}
}
+ return NULL;
+
+
+// struct_8018D9E0_entry *entry = D_8018D9E0;
+// for (; !(entry > (&D_8018D9E0[D_8018D9E0_SIZE])); entry++) {
+// if (entry->type == arg0) {
+// goto escape;
+// }
+// }
// Something VERY wrong has occurred
- while(true);
-escape:
- return entry;
+// while(true);
+//escape:
+// return entry;
}
struct_8018D9E0_entry *find_8018D9E0_entry(s32 arg0) {
- struct_8018D9E0_entry *entry = D_8018D9E0;
- for (; !(entry > (&D_8018D9E0[D_8018D9E0_SIZE])); entry++) {
- if (entry->type == arg0) {
- goto escape;
+ for (size_t i = 0; i < ARRAY_COUNT(D_8018D9E0); i++) {
+ if (&D_8018D9E0[i].type == arg0) {
+ return &D_8018D9E0[i];
}
}
-
return NULL;
-escape:
- return entry;
+
+// struct_8018D9E0_entry *entry = D_8018D9E0;
+// for (; !(entry > (&D_8018D9E0[D_8018D9E0_SIZE])); entry++) {
+// if (entry->type == arg0) {
+// goto escape;
+// }
+// }
+
+// return NULL;
+//escape:
+// return entry;
}
s32 func_800AAF70(s32 arg0) {
diff --git a/src/code_80091750.h b/src/code_80091750.h
index 157fc607c..d5632677a 100644
--- a/src/code_80091750.h
+++ b/src/code_80091750.h
@@ -59,7 +59,7 @@ typedef struct {
} struct_8018E0E8_entry; //size = 0x8
typedef struct {
- /* 0x00 */ u64 *textureData; // This should be interpreted as a segmented address
+ /* 0x00 */ const char *textureData; // This should be interpreted as a segmented address
/**
* Its hard to tell what exactly what this is meant to be,
* but it appears to be used as some sort of offset/index from the address stored in D_8018D9B0.
@@ -426,7 +426,7 @@ extern s8 D_8018D9D8;
extern s8 D_8018D9D9;
extern struct_8018D9E0_entry D_8018D9E0[D_8018D9E0_SIZE];
extern struct_8018DEE0_entry D_8018DEE0[D_8018DEE0_SIZE];
-extern struct_8018E060_entry D_8018E060[D_8018E060_SIZE];
+extern struct_8018E060_entry D_8018E060[];
extern struct_8018E0E8_entry D_8018E0E8[D_8018E0E8_SIZE];
extern s32 gD_8018E118TotalSize;
extern struct_8018E118_entry D_8018E118[D_8018E118_SIZE];
diff --git a/src/code_800AF9B0.c b/src/code_800AF9B0.c
index faac24fc7..6aabd3757 100644
--- a/src/code_800AF9B0.c
+++ b/src/code_800AF9B0.c
@@ -10,17 +10,7 @@
#include "math_util.h"
#include <stdlib.h>
-/*** Data ***/
-Ambient D_800E8680 = {{
- {31, 31, 31}, 0,
- {31, 31, 31}, 0,
-}};
-
-Light D_800E8688 = {{
- {255, 255, 255}, 0,
- {255, 255, 255}, 0,
- { 40, 40, 20}, 0,
-}};
+Lights1 D_800E8680 = gdSPDefLights1(31, 31, 31, 255, 255, 255, 40, 40, 20);
/*** BSS ****/
s16 D_8018EDB0;
@@ -173,8 +163,8 @@ void func_800B0004(void) {
UNUSED u32 pad[0x5];
s32 i, j;
- gSPLight(gDisplayListHead++, VIRTUAL_TO_PHYSICAL2(&D_800E8688), LIGHT_1);
- gSPLight(gDisplayListHead++, VIRTUAL_TO_PHYSICAL2(&D_800E8680), LIGHT_2);
+ gSPLight(gDisplayListHead++, VIRTUAL_TO_PHYSICAL2(&D_800E8680.l[0]), LIGHT_1);
+ gSPLight(gDisplayListHead++, VIRTUAL_TO_PHYSICAL2(&D_800E8680.a), LIGHT_2);
gSPNumLights(gDisplayListHead++, NUMLIGHTS_1);
gSPSetGeometryMode(gDisplayListHead++, G_SHADE | G_SHADING_SMOOTH);
gDPSetCombineLERP(gDisplayListHead++, PRIMITIVE, 0, SHADE, 0, 0, 0, 0, SHADE, PRIMITIVE, 0, SHADE, 0, 0, 0, 0, SHADE);