mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-22 03:55:11 +00:00
Fixed smlua_model_util_get_id buffer overflow (#404)
- added the missing limit check for `sCustomModelsCount` (caused memory overflow into `bbh_seg7_vertex_`) - changed `LOG_ERROR` to `LOG_LUA_LINE`, so that the mod dev can easily see any missing models (similar to getting warnings about missing audio files with `audio_sample_load`)
This commit is contained in:
parent
b8381cf198
commit
42cf0e3eea
1 changed files with 8 additions and 3 deletions
|
@ -53,7 +53,7 @@
|
||||||
#include "levels/ttm/header.h"
|
#include "levels/ttm/header.h"
|
||||||
|
|
||||||
#include "smlua_model_utils.h"
|
#include "smlua_model_utils.h"
|
||||||
#include "pc/debuglog.h"
|
#include "pc/lua/smlua.h"
|
||||||
|
|
||||||
struct ModelUtilsInfo {
|
struct ModelUtilsInfo {
|
||||||
enum ModelExtendedId extId;
|
enum ModelExtendedId extId;
|
||||||
|
@ -463,8 +463,8 @@ struct ModelUtilsInfo sModels[E_MODEL_MAX] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_CUSTOM_MODELS 256
|
#define MAX_CUSTOM_MODELS 256
|
||||||
struct ModelUtilsInfo sCustomModels[MAX_CUSTOM_MODELS] = { 0 };
|
|
||||||
static u16 sCustomModelsCount = 0;
|
static u16 sCustomModelsCount = 0;
|
||||||
|
struct ModelUtilsInfo sCustomModels[MAX_CUSTOM_MODELS] = { 0 };
|
||||||
|
|
||||||
void smlua_model_util_clear(void) {
|
void smlua_model_util_clear(void) {
|
||||||
sCustomModelsCount = 0;
|
sCustomModelsCount = 0;
|
||||||
|
@ -497,7 +497,7 @@ enum ModelExtendedId smlua_model_util_get_id(const char* name) {
|
||||||
// find geolayout
|
// find geolayout
|
||||||
const void* asset = dynos_geolayout_get(name);
|
const void* asset = dynos_geolayout_get(name);
|
||||||
if (asset == NULL) {
|
if (asset == NULL) {
|
||||||
LOG_ERROR("Failed to find model: %s - %u", name, E_MODEL_ERROR_MODEL);
|
LOG_LUA_LINE("Could not find model: '%s'", name);
|
||||||
return E_MODEL_ERROR_MODEL;
|
return E_MODEL_ERROR_MODEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,6 +517,11 @@ enum ModelExtendedId smlua_model_util_get_id(const char* name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sCustomModelsCount >= MAX_CUSTOM_MODELS) {
|
||||||
|
LOG_LUA("Failed to get model: '%s' (too many custom models!)", name);
|
||||||
|
return E_MODEL_ERROR_MODEL;
|
||||||
|
}
|
||||||
|
|
||||||
// allocate custom model
|
// allocate custom model
|
||||||
u16 customIndex = sCustomModelsCount++;
|
u16 customIndex = sCustomModelsCount++;
|
||||||
struct ModelUtilsInfo* info = &sCustomModels[customIndex];
|
struct ModelUtilsInfo* info = &sCustomModels[customIndex];
|
||||||
|
|
Loading…
Reference in a new issue