mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-08-13 19:44:32 -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
@@ -14,7 +14,10 @@
|
||||
#include "m_Do/m_Do_controller_pad.h"
|
||||
#include <cstring>
|
||||
|
||||
// Need 0xC bytes of padding with no symbol between dMenu_Calibration_c::__vtable and the end of .data
|
||||
#include "dusk/string.hpp"
|
||||
|
||||
// Need 0xC bytes of padding with no symbol between dMenu_Calibration_c::__vtable and the end of
|
||||
// .data
|
||||
// This is likely caused by the vtable of an abstract base class getting put there and then stripped out.
|
||||
// Not sure which abstract base class could go there though, so we simulate it with some dummy classes for now.
|
||||
class dummy_abstract_class {
|
||||
@@ -252,7 +255,7 @@ void dMenu_Calibration_c::setCalibrationValue() {
|
||||
void dMenu_Calibration_c::setAButtonString(u16 i_stringID) {
|
||||
if (i_stringID == 0) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
strcpy(mpAButtonString[i]->getStringPtr(), "");
|
||||
SAFE_STRCPY(mpAButtonString[i]->getStringPtr(), "");
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
@@ -264,7 +267,7 @@ void dMenu_Calibration_c::setAButtonString(u16 i_stringID) {
|
||||
void dMenu_Calibration_c::setBButtonString(u16 i_stringID) {
|
||||
if (i_stringID == 0) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
strcpy(mpBButtonString[i]->getStringPtr(), "");
|
||||
SAFE_STRCPY(mpBButtonString[i]->getStringPtr(), "");
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
@@ -276,7 +279,7 @@ void dMenu_Calibration_c::setBButtonString(u16 i_stringID) {
|
||||
void dMenu_Calibration_c::setStepString(u16 i_stringID) {
|
||||
if (i_stringID == 0) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
strcpy(mpStepString[i]->getStringPtr(), "");
|
||||
SAFE_STRCPY(mpStepString[i]->getStringPtr(), "");
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@@ -288,7 +291,7 @@ void dMenu_Calibration_c::setStepString(u16 i_stringID) {
|
||||
void dMenu_Calibration_c::setExplainString(u16 i_stringID) {
|
||||
if (i_stringID == 0) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
strcpy(mpExplainString[i]->getStringPtr(), "");
|
||||
SAFE_STRCPY(mpExplainString[i]->getStringPtr(), "");
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
||||
Reference in New Issue
Block a user