mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-28 06:57:02 -04:00
String safety (#1548)
* Array size UB fixes * Fix ShieldD * Remove (almost) all unsafe strcpy calls Bunch of macros. C arrays are easy enough and just need a different call. For various cases where a char* is passed around bare, I've made a TEXT_SPAN macro that can store a length too for bounds checking. * Move crash handling in safe string operations to separate TU * strcat safe version * sprintf made safe too * Fix compile
This commit is contained in:
committed by
GitHub
parent
af162bbd0a
commit
a6376368ee
@@ -15,6 +15,8 @@
|
||||
#include "SSystem/SComponent/c_counter.h"
|
||||
#include <cstring>
|
||||
|
||||
#include "dusk/string.hpp"
|
||||
|
||||
#if DEBUG
|
||||
static dEvM_HIO_c l_HIO;
|
||||
#endif
|
||||
@@ -388,7 +390,7 @@ void dEvent_manager_c::roomInit(int roomNo) {
|
||||
}
|
||||
|
||||
char arcname[8];
|
||||
strcpy(arcname, dComIfG_getRoomArcName(roomNo));
|
||||
SAFE_STRCPY(arcname, dComIfG_getRoomArcName(roomNo));
|
||||
char* res = (char*)dComIfG_getStageRes(arcname, DataFileName);
|
||||
|
||||
int i;
|
||||
@@ -836,7 +838,7 @@ s16 dEvent_manager_c::getEventIdx(const char* eventName, u8 mapToolID, s32 roomN
|
||||
case dStage_MapEvent_dt_TYPE_STB:
|
||||
return getEventIdx(mapdata->data.event_name, 0xFF, roomNo);
|
||||
case dStage_MapEvent_dt_TYPE_MAPTOOLCAMERA:
|
||||
sprintf(map_tool_name, "MapToolCamera%d", mapToolID);
|
||||
SAFE_SPRINTF(map_tool_name, "MapToolCamera%d", mapToolID);
|
||||
return getEventIdx(map_tool_name, 0xFF, roomNo);
|
||||
default:
|
||||
JUT_ASSERT(1278, FALSE);
|
||||
@@ -876,7 +878,7 @@ s16 dEvent_manager_c::getEventIdx(fopAc_ac_c* actor, u8 mapToolID) {
|
||||
case dStage_MapEvent_dt_TYPE_STB:
|
||||
return getEventIdx(actor, mapdata->data.event_name, 0xFF);
|
||||
case dStage_MapEvent_dt_TYPE_MAPTOOLCAMERA:
|
||||
sprintf(map_tool_name, "MapToolCamera%d", mapToolID);
|
||||
SAFE_SPRINTF(map_tool_name, "MapToolCamera%d", mapToolID);
|
||||
return getEventIdx(actor, map_tool_name, 0xFF);
|
||||
default:
|
||||
JUT_ASSERT(1341, FALSE);
|
||||
@@ -901,7 +903,7 @@ s16 dEvent_manager_c::getEventIdx(fopAc_ac_c* actor, const char* eventName, u8 m
|
||||
case dStage_MapEvent_dt_TYPE_STB:
|
||||
return getEventIdx(actor, mapdata->data.event_name, 0xFF);
|
||||
case dStage_MapEvent_dt_TYPE_MAPTOOLCAMERA:
|
||||
sprintf(map_tool_name, "MapToolCamera%d", mapToolID);
|
||||
SAFE_SPRINTF(map_tool_name, "MapToolCamera%d", mapToolID);
|
||||
return getEventIdx(actor, map_tool_name, 0xFF);
|
||||
default:
|
||||
JUT_ASSERT(1376, FALSE);
|
||||
@@ -1040,7 +1042,7 @@ int dEvent_manager_c::getMyStaffId(const char* staffName, fopAc_ac_c* actor, int
|
||||
dEvDtStaff_c* staff = getBase().getStaffP(staff_id);
|
||||
if (staff->getType() != dEvDtStaff_c::TYPE_ALL) {
|
||||
char buf[20];
|
||||
strcpy(buf, staff->getName());
|
||||
SAFE_STRCPY(buf, staff->getName());
|
||||
|
||||
char* ptr = NULL;
|
||||
if (!hasDp) {
|
||||
@@ -1310,7 +1312,7 @@ void dEvent_manager_c::issueStaff(const char* staffname) {
|
||||
fopAcM_Search((fopAcIt_JudgeFunc)extraOnObjectCallBack, NULL);
|
||||
} else {
|
||||
char nameBuf[32];
|
||||
strcpy(nameBuf, staffname);
|
||||
SAFE_STRCPY(nameBuf, staffname);
|
||||
fopAc_ac_c* actor = fopAcM_searchFromName4Event(nameBuf, -1);
|
||||
fopAcM_OnStatus(actor, fopAcStts_STAFF_EXTRA_e);
|
||||
}
|
||||
@@ -1321,7 +1323,7 @@ void dEvent_manager_c::cancelStaff(const char* staffname) {
|
||||
fopAcM_Search((fopAcIt_JudgeFunc)extraOffObjectCallBack, NULL);
|
||||
} else {
|
||||
char nameBuf[32];
|
||||
strcpy(nameBuf, staffname);
|
||||
SAFE_STRCPY(nameBuf, staffname);
|
||||
fopAc_ac_c* actor = fopAcM_searchFromName4Event(nameBuf, -1);
|
||||
fopAcM_OffStatus(actor, fopAcStts_STAFF_EXTRA_e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user