From a893ad05e393c4c7654d1b5db1b929986ef85ba0 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Mon, 7 Sep 2020 11:23:05 -0700 Subject: [PATCH] Use strlcpy and strlcat in the Mac port --- macosx/mac-file.mm | 38 +++++++++++++++++++------------------- macosx/mac-musicbox.mm | 12 ++++++------ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/macosx/mac-file.mm b/macosx/mac-file.mm index 2d6c8fa34..74466db27 100644 --- a/macosx/mac-file.mm +++ b/macosx/mac-file.mm @@ -231,38 +231,38 @@ static void AddFolderIcon (NSURL *fref, const char *folderName) { case '.srm': case '.rtc': - strcpy(folderName, "SRAMs"); + strlcpy(folderName, "SRAMs", sizeof(folderName)); break; case '.frz': - strcpy(folderName, "Freezes"); + strlcpy(folderName, "Freezes", sizeof(folderName)); break; case '.spc': - strcpy(folderName, "SPCs"); + strlcpy(folderName, "SPCs", sizeof(folderName)); break; case '.cht': - strcpy(folderName, "Cheats"); + strlcpy(folderName, "Cheats", sizeof(folderName)); break; case '.ups': case '.ips': - strcpy(folderName, "Patches"); + strlcpy(folderName, "Patches", sizeof(folderName)); break; case '.png': - strcpy(folderName, "Screenshots"); + strlcpy(folderName, "Screenshots", sizeof(folderName)); break; case '.dat': case '.out': case '.log': - strcpy(folderName, "Logs"); + strlcpy(folderName, "Logs", sizeof(folderName)); break; case '.bio': // dummy - strcpy(folderName, "BIOSes"); + strlcpy(folderName, "BIOSes", sizeof(folderName)); break; } @@ -296,7 +296,7 @@ static void AddFolderIcon (NSURL *fref, const char *folderName) { _splitpath(Memory.ROMFilename, drive, dir, fname, ext); - strcat(fname, inExt); + strlcat(fname, inExt, sizeof(fname)); _makepath(filePath[index], drive, dir, fname, ""); } } @@ -304,7 +304,7 @@ static void AddFolderIcon (NSURL *fref, const char *folderName) { _splitpath(Memory.ROMFilename, drive, dir, fname, ext); - strcat(fname, inExt); + strlcat(fname, inExt, sizeof(fname)); _makepath(filePath[index], drive, dir, fname, ""); } @@ -394,7 +394,7 @@ void S9xCloseSnapshotFile (STREAM file) { static char s[PATH_MAX + 1]; - strncpy(s, in, PATH_MAX + 1); + strlcpy(s, in, sizeof(s)); s[PATH_MAX] = 0; size_t l = strlen(s); @@ -422,14 +422,14 @@ void S9xCloseSnapshotFile (STREAM file) switch (dirtype) { - case SNAPSHOT_DIR: strcpy(inExt, ".frz"); break; - case SRAM_DIR: strcpy(inExt, ".srm"); break; - case SCREENSHOT_DIR: strcpy(inExt, ".png"); break; - case SPC_DIR: strcpy(inExt, ".spc"); break; - case CHEAT_DIR: strcpy(inExt, ".cht"); break; - case BIOS_DIR: strcpy(inExt, ".bio"); break; - case LOG_DIR: strcpy(inExt, ".log"); break; - default: strcpy(inExt, ".xxx"); break; + case SNAPSHOT_DIR: strlcpy(inExt, ".frz", sizeof(inExt)); break; + case SRAM_DIR: strlcpy(inExt, ".srm", sizeof(inExt)); break; + case SCREENSHOT_DIR: strlcpy(inExt, ".png", sizeof(inExt)); break; + case SPC_DIR: strlcpy(inExt, ".spc", sizeof(inExt)); break; + case CHEAT_DIR: strlcpy(inExt, ".cht", sizeof(inExt)); break; + case BIOS_DIR: strlcpy(inExt, ".bio", sizeof(inExt)); break; + case LOG_DIR: strlcpy(inExt, ".log", sizeof(inExt)); break; + default: strlcpy(inExt, ".xxx", sizeof(inExt)); break; } _splitpath(S9xGetFilename(inExt, dirtype), drive, dir, fname, ext); diff --git a/macosx/mac-musicbox.mm b/macosx/mac-musicbox.mm index d9201c067..615fa680e 100755 --- a/macosx/mac-musicbox.mm +++ b/macosx/mac-musicbox.mm @@ -414,20 +414,20 @@ static void SPCPlayExec (void) static void MusicBoxForceFreeze (void) { - char filename[PATH_MAX + 1]; + char filename[PATH_MAX + 1]; - strcpy(filename, S9xGetFreezeFilename(999)); - strcat(filename, ".tmp"); + strlcpy(filename, S9xGetFreezeFilename(999), sizeof(filename)); + strlcat(filename, ".tmp", sizeof(filename)); S9xFreezeGame(filename); } static void MusicBoxForceDefrost (void) { - char filename[PATH_MAX + 1]; + char filename[PATH_MAX + 1]; - strcpy(filename, S9xGetFreezeFilename(999)); - strcat(filename, ".tmp"); + strlcpy(filename, S9xGetFreezeFilename(999), sizeof(filename)); + strlcat(filename, ".tmp", sizeof(filename)); S9xUnfreezeGame(filename); remove(filename);