All: Fix handling of strncat bounds

This commit is contained in:
Vicki Pfau 2023-03-01 20:16:40 -08:00
parent 064d6ce183
commit bba57ce530
5 changed files with 10 additions and 10 deletions

View File

@ -169,14 +169,14 @@ void mCoreConfigDeinit(struct mCoreConfig* config) {
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
bool mCoreConfigLoad(struct mCoreConfig* config) {
char path[PATH_MAX];
char path[PATH_MAX + 1];
mCoreConfigDirectory(path, PATH_MAX);
strncat(path, PATH_SEP "config.ini", PATH_MAX - strlen(path));
return mCoreConfigLoadPath(config, path);
}
bool mCoreConfigSave(const struct mCoreConfig* config) {
char path[PATH_MAX];
char path[PATH_MAX + 1];
mCoreConfigDirectory(path, PATH_MAX);
strncat(path, PATH_SEP "config.ini", PATH_MAX - strlen(path));
return mCoreConfigSavePath(config, path);
@ -304,7 +304,7 @@ void mCoreConfigPortablePath(char* out, size_t outLength) {
CFRelease(suburl);
}
#endif
strncat(out, PATH_SEP "portable.ini", outLength - strlen(out));
strncat(out, PATH_SEP "portable.ini", outLength - strlen(out) - 1);
#endif
}

View File

@ -114,7 +114,7 @@ int main(int argc, char* argv[]) {
int ok = 1;
mCoreConfigDirectory(bin, sizeof(bin));
strncat(bin, "/updater.log", sizeof(bin));
strncat(bin, "/updater.log", sizeof(bin) - 1);
logfile = fopen(bin, "w");
mCoreConfigInit(&config, "updater");

View File

@ -607,16 +607,16 @@ static void _GBCoreReset(struct mCore* core) {
switch (gb->model) {
case GB_MODEL_DMG:
case GB_MODEL_MGB: // TODO
strncat(path, PATH_SEP "gb_bios.bin", PATH_MAX - strlen(path));
strncat(path, PATH_SEP "gb_bios.bin", PATH_MAX - strlen(path) - 1);
break;
case GB_MODEL_SGB:
case GB_MODEL_SGB2: // TODO
strncat(path, PATH_SEP "sgb_bios.bin", PATH_MAX - strlen(path));
strncat(path, PATH_SEP "sgb_bios.bin", PATH_MAX - strlen(path) - 1);
break;
case GB_MODEL_CGB:
case GB_MODEL_AGB:
case GB_MODEL_SCGB:
strncat(path, PATH_SEP "gbc_bios.bin", PATH_MAX - strlen(path));
strncat(path, PATH_SEP "gbc_bios.bin", PATH_MAX - strlen(path) - 1);
break;
default:
break;

View File

@ -684,7 +684,7 @@ static void _GBACoreReset(struct mCore* core) {
if (!found) {
char path[PATH_MAX];
mCoreConfigDirectory(path, PATH_MAX);
strncat(path, PATH_SEP "gba_bios.bin", PATH_MAX - strlen(path));
strncat(path, PATH_SEP "gba_bios.bin", PATH_MAX - strlen(path) - 1);
bios = VFileOpen(path, O_RDONLY);
if (bios && GBAIsBIOS(bios)) {
found = true;

View File

@ -149,7 +149,7 @@ MAKE_SCALAR_SETTER(Bool, BOOL)
void mScriptStorageGetBucketPath(const char* bucket, char* out) {
mCoreConfigDirectory(out, PATH_MAX);
strncat(out, PATH_SEP "storage" PATH_SEP, PATH_MAX);
strncat(out, PATH_SEP "storage" PATH_SEP, PATH_MAX - 1);
#ifdef _WIN32
// TODO: Move this to vfs somewhere
WCHAR wout[MAX_PATH];
@ -161,7 +161,7 @@ void mScriptStorageGetBucketPath(const char* bucket, char* out) {
char suffix[STORAGE_LEN_MAX + 6];
snprintf(suffix, sizeof(suffix), "%s.json", bucket);
strncat(out, suffix, PATH_MAX);
strncat(out, suffix, PATH_MAX - 1);
}
static struct json_object* _tableToJson(struct mScriptValue* rootVal) {