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:
Pieter-Jan Briers
2026-05-24 18:43:00 +02:00
committed by GitHub
parent af162bbd0a
commit a6376368ee
100 changed files with 781 additions and 546 deletions
+4 -4
View File
@@ -816,8 +816,8 @@ void dMenu_save_c::saveQuestion() {
field_0x9c = 0;
field_0x17a = 0;
strcpy(mpHeaderTxt[mHeaderTxtType], "");
strcpy(mpHeaderTxt[mHeaderTxtType ^ 1], "");
SAFE_STRCPY(mpHeaderTxt[mHeaderTxtType], "");
SAFE_STRCPY(mpHeaderTxt[mHeaderTxtType ^ 1], "");
field_0x64 = 0;
field_0x50 = 1;
field_0x40->setFrame(field_0x50);
@@ -2033,7 +2033,7 @@ void dMenu_save_c::saveYesNoCancelMove() {
void dMenu_save_c::headerTxtSet(u16 msgID) {
if (msgID == 0xFFFF) {
strcpy(mpHeaderTxt[mHeaderTxtType ^ 1], "");
SAFE_STRCPY(mpHeaderTxt[mHeaderTxtType ^ 1], "");
} else {
mSaveSel.mMsgString->getString(
msgID, (J2DTextBox*)mpHeaderTxtPane[mHeaderTxtType ^ 1]->getPanePtr(), NULL,
@@ -2230,7 +2230,7 @@ void dMenu_save_c::errYesNoCursorMoveAnm() {
void dMenu_save_c::errorTxtSet(u16 msgID) {
if (msgID == 0xFFFF) {
strcpy(mpErrTxt[mErrTxtType ^ 1], "");
SAFE_STRCPY(mpErrTxt[mErrTxtType ^ 1], "");
} else {
J2DTextBox* tbox = (J2DTextBox*)mpErrTxtPane[mErrTxtType ^ 1]->getPanePtr();
mSaveSel.mMsgString->getString(msgID, tbox, NULL, mSaveSel.font[0], NULL, 0);