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
@@ -8,6 +8,8 @@
#include <cstring>
#include <types.h>
#include "dusk/string.hpp"
J2DMaterialFactory::J2DMaterialFactory(J2DMaterialBlock const& param_0) {
mMaterialNum = param_0.field_0x8;
mpMaterialInitData = JSUConvertOffsetToPtr<J2DMaterialInitData>(&param_0, param_0.field_0xc);
@@ -92,7 +94,7 @@ J2DMaterial* J2DMaterialFactory::create(J2DMaterial* param_0, int index, u32 par
}
if (local_380 == NULL && J2DScreen::getDataManage() != NULL) {
char acStack_230[257];
strcpy(acStack_230, param_3->getName(texNo));
SAFE_STRCPY(acStack_230, param_3->getName(texNo));
local_380 = J2DScreen::getDataManage()->get(acStack_230);
}
}
@@ -111,7 +113,7 @@ J2DMaterial* J2DMaterialFactory::create(J2DMaterial* param_0, int index, u32 par
}
if (local_388 == NULL && J2DScreen::getDataManage() != NULL) {
char acStack_334[257];
strcpy(acStack_334, param_4->getName(param_0->getTevBlock()->getFontNo()));
SAFE_STRCPY(acStack_334, param_4->getName(param_0->getTevBlock()->getFontNo()));
local_388 = J2DScreen::getDataManage()->get(acStack_334);
}
}