mirror of https://github.com/snes9xgit/snes9x.git
String bounds-checking.
This commit is contained in:
parent
7bb5b00504
commit
600de05244
12
controls.cpp
12
controls.cpp
|
@ -2282,11 +2282,11 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2)
|
||||||
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], def[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
|
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], def[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
|
||||||
|
|
||||||
_splitpath(Memory.ROMFilename, drive, dir, def, ext);
|
_splitpath(Memory.ROMFilename, drive, dir, def, ext);
|
||||||
snprintf(filename, PATH_MAX + 1, "%s%s%s.%.*s", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, _MAX_EXT - 1, "oops");
|
ssnprintf(filename, PATH_MAX + 1, "%s%s%s.%.*s", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, _MAX_EXT - 1, "oops");
|
||||||
|
|
||||||
if (S9xUnfreezeGame(filename))
|
if (S9xUnfreezeGame(filename))
|
||||||
{
|
{
|
||||||
snprintf(buf, 256, "%s.%.*s loaded", def, _MAX_EXT - 1, "oops");
|
ssnprintf(buf, 256, "%s.%.*s loaded", def, _MAX_EXT - 1, "oops");
|
||||||
S9xSetInfoString (buf);
|
S9xSetInfoString (buf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2319,11 +2319,11 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2)
|
||||||
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], def[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
|
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], def[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
|
||||||
|
|
||||||
_splitpath(Memory.ROMFilename, drive, dir, def, ext);
|
_splitpath(Memory.ROMFilename, drive, dir, def, ext);
|
||||||
snprintf(filename, PATH_MAX + 1, "%s%s%s.%03d", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, i - QuickLoad000);
|
ssnprintf(filename, PATH_MAX + 1, "%s%s%s.%03d", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, i - QuickLoad000);
|
||||||
|
|
||||||
if (S9xUnfreezeGame(filename))
|
if (S9xUnfreezeGame(filename))
|
||||||
{
|
{
|
||||||
snprintf(buf, 256, "%s.%03d loaded", def, i - QuickLoad000);
|
ssnprintf(buf, 256, "%s.%03d loaded", def, i - QuickLoad000);
|
||||||
S9xSetInfoString(buf);
|
S9xSetInfoString(buf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2348,9 +2348,9 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2)
|
||||||
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], def[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
|
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], def[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
|
||||||
|
|
||||||
_splitpath(Memory.ROMFilename, drive, dir, def, ext);
|
_splitpath(Memory.ROMFilename, drive, dir, def, ext);
|
||||||
snprintf(filename, PATH_MAX + 1, "%s%s%s.%03d", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, i - QuickSave000);
|
ssnprintf(filename, PATH_MAX + 1, "%s%s%s.%03d", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, i - QuickSave000);
|
||||||
|
|
||||||
snprintf(buf, 256, "%s.%03d saved", def, i - QuickSave000);
|
ssnprintf(buf, 256, "%s.%03d saved", def, i - QuickSave000);
|
||||||
S9xSetInfoString(buf);
|
S9xSetInfoString(buf);
|
||||||
|
|
||||||
S9xFreezeGame(filename);
|
S9xFreezeGame(filename);
|
||||||
|
|
|
@ -15,17 +15,21 @@ static char buf[PATH_MAX];
|
||||||
const char *
|
const char *
|
||||||
S9xChooseMovieFilename (bool8 read_only)
|
S9xChooseMovieFilename (bool8 read_only)
|
||||||
{
|
{
|
||||||
if (!gui_config->rom_loaded)
|
static char path[PATH_MAX];
|
||||||
return strdup ("");
|
|
||||||
|
|
||||||
return top_level->open_movie_dialog (read_only);
|
if (!gui_config->rom_loaded)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
const char *str = top_level->open_movie_dialog (read_only);
|
||||||
|
strcpy (path, str);
|
||||||
|
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
S9xChooseFilename (bool8 read_only)
|
S9xChooseFilename (bool8 read_only)
|
||||||
{
|
{
|
||||||
|
return "";
|
||||||
return strdup ("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _splitpath/_makepath: Modified from unix.cpp. See file for credits. */
|
/* _splitpath/_makepath: Modified from unix.cpp. See file for credits. */
|
||||||
|
@ -120,8 +124,7 @@ S9xGetFilenameInc (const char *e, enum s9x_getdirtype dirtype)
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
snprintf (filename, sizeof (filename),
|
ssnprintf (filename, PATH_MAX, "%s" SLASH_STR "%s%03d%s", d, fname, i, e);
|
||||||
"%s" SLASH_STR "%s%03d%s", d, fname, i, e);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
while (stat (filename, &buf) == 0 && i != 0); /* Overflow? ...riiight :-) */
|
while (stat (filename, &buf) == 0 && i != 0); /* Overflow? ...riiight :-) */
|
||||||
|
@ -211,7 +214,7 @@ S9xGetFilename (const char *ex, enum s9x_getdirtype dirtype)
|
||||||
|
|
||||||
_splitpath (Memory.ROMFilename, drive, dir, fname, ext);
|
_splitpath (Memory.ROMFilename, drive, dir, fname, ext);
|
||||||
|
|
||||||
snprintf (filename, sizeof (filename), "%s" SLASH_STR "%s%s",
|
ssnprintf (filename, sizeof (filename), "%s" SLASH_STR "%s%s",
|
||||||
S9xGetDirectory (dirtype), fname, ex);
|
S9xGetDirectory (dirtype), fname, ex);
|
||||||
|
|
||||||
return (filename);
|
return (filename);
|
||||||
|
@ -360,21 +363,6 @@ void S9xCloseSnapshotFile (STREAM file)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
uint8 snes9x_clear_change_log = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" char *osd_GetPackDir ()
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
S9xLoadSDD1Data ()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
S9xAutoSaveSRAM ()
|
S9xAutoSaveSRAM ()
|
||||||
{
|
{
|
||||||
|
@ -468,7 +456,7 @@ S9xOpenROMDialog ()
|
||||||
gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
|
gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
|
||||||
if (directory)
|
if (directory)
|
||||||
{
|
{
|
||||||
strncpy (gui_config->last_directory, directory, PATH_MAX);
|
strncpy (gui_config->last_directory, directory, PATH_MAX - 1);
|
||||||
g_free (directory);
|
g_free (directory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -500,13 +488,13 @@ S9xQuickSaveSlot (int slot)
|
||||||
|
|
||||||
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
|
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
|
||||||
|
|
||||||
snprintf (filename, PATH_MAX, "%s%s%s.%03d",
|
ssnprintf (filename, PATH_MAX, "%s%s%s.%03d",
|
||||||
S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR, def,
|
S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR, def,
|
||||||
slot);
|
slot);
|
||||||
|
|
||||||
if (S9xFreezeGame (filename))
|
if (S9xFreezeGame (filename))
|
||||||
{
|
{
|
||||||
snprintf (buf, PATH_MAX, "%s.%03d saved", def, slot);
|
ssnprintf (buf, PATH_MAX, "%s.%03d saved", def, slot);
|
||||||
|
|
||||||
S9xSetInfoString (buf);
|
S9xSetInfoString (buf);
|
||||||
}
|
}
|
||||||
|
@ -525,7 +513,7 @@ void S9xQuickLoadSlot (int slot)
|
||||||
|
|
||||||
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
|
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
|
||||||
|
|
||||||
snprintf (filename, PATH_MAX, "%s%s%s.%03d",
|
ssnprintf (filename, PATH_MAX, "%s%s%s.%03d",
|
||||||
S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR, def,
|
S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR, def,
|
||||||
slot);
|
slot);
|
||||||
|
|
||||||
|
@ -534,7 +522,7 @@ void S9xQuickLoadSlot (int slot)
|
||||||
|
|
||||||
if (S9xUnfreezeGame (filename))
|
if (S9xUnfreezeGame (filename))
|
||||||
{
|
{
|
||||||
snprintf (buf, PATH_MAX, "%s.%03d loaded", def, slot);
|
ssnprintf (buf, PATH_MAX, "%s.%03d loaded", def, slot);
|
||||||
S9xSetInfoString (buf);
|
S9xSetInfoString (buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -543,7 +531,7 @@ void S9xQuickLoadSlot (int slot)
|
||||||
|
|
||||||
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
|
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
|
||||||
|
|
||||||
snprintf (filename, PATH_MAX, "%s%s%s.zs%c",
|
ssnprintf (filename, PATH_MAX, "%s%s%s.zs%c",
|
||||||
S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR,
|
S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR,
|
||||||
def, digits[slot]);
|
def, digits[slot]);
|
||||||
|
|
||||||
|
@ -552,7 +540,7 @@ void S9xQuickLoadSlot (int slot)
|
||||||
|
|
||||||
if (S9xUnfreezeGame (filename))
|
if (S9xUnfreezeGame (filename))
|
||||||
{
|
{
|
||||||
snprintf (buf, PATH_MAX,
|
ssnprintf (buf, PATH_MAX,
|
||||||
"Loaded ZSNES freeze file %s.zs%c",
|
"Loaded ZSNES freeze file %s.zs%c",
|
||||||
def, digits [slot]);
|
def, digits [slot]);
|
||||||
S9xSetInfoString (buf);
|
S9xSetInfoString (buf);
|
||||||
|
|
|
@ -96,8 +96,8 @@ Snes9xNetplayDialog::settings_to_dialog ()
|
||||||
void
|
void
|
||||||
Snes9xNetplayDialog::settings_from_dialog ()
|
Snes9xNetplayDialog::settings_from_dialog ()
|
||||||
{
|
{
|
||||||
strncpy (config->netplay_last_rom, get_entry_text ("rom_image"), PATH_MAX);
|
strncpy (config->netplay_last_rom, get_entry_text ("rom_image"), PATH_MAX - 1);
|
||||||
strncpy (config->netplay_last_host, get_entry_text ("ip_entry"), PATH_MAX);
|
strncpy (config->netplay_last_host, get_entry_text ("ip_entry"), PATH_MAX - 1);
|
||||||
config->netplay_sync_reset = get_check ("sync_reset");
|
config->netplay_sync_reset = get_check ("sync_reset");
|
||||||
config->netplay_send_rom = get_check ("send_image");
|
config->netplay_send_rom = get_check ("send_image");
|
||||||
config->netplay_last_port = get_spin ("port");
|
config->netplay_last_port = get_spin ("port");
|
||||||
|
|
|
@ -905,17 +905,17 @@ Snes9xPreferences::get_settings_from_dialog ()
|
||||||
config->use_shaders = get_check ("use_shaders");
|
config->use_shaders = get_check ("use_shaders");
|
||||||
config->sync_every_frame = get_check ("sync_every_frame");
|
config->sync_every_frame = get_check ("sync_every_frame");
|
||||||
|
|
||||||
strncpy (config->fragment_shader, get_entry_text ("fragment_shader"), PATH_MAX);
|
strncpy (config->fragment_shader, get_entry_text ("fragment_shader"), PATH_MAX - 1);
|
||||||
|
|
||||||
config->pbo_format = pbo_format;
|
config->pbo_format = pbo_format;
|
||||||
#endif
|
#endif
|
||||||
char safety_sram_directory [PATH_MAX];
|
char safety_sram_directory [PATH_MAX];
|
||||||
|
|
||||||
strncpy (safety_sram_directory, get_entry_text ("sram_directory"), PATH_MAX);
|
strncpy (safety_sram_directory, get_entry_text ("sram_directory"), PATH_MAX - 1);
|
||||||
strncpy (config->savestate_directory, get_entry_text ("savestate_directory"), PATH_MAX);
|
strncpy (config->savestate_directory, get_entry_text ("savestate_directory"), PATH_MAX - 1);
|
||||||
strncpy (config->patch_directory, get_entry_text ("patch_directory"), PATH_MAX);
|
strncpy (config->patch_directory, get_entry_text ("patch_directory"), PATH_MAX - 1);
|
||||||
strncpy (config->cheat_directory, get_entry_text ("cheat_directory"), PATH_MAX);
|
strncpy (config->cheat_directory, get_entry_text ("cheat_directory"), PATH_MAX - 1);
|
||||||
strncpy (config->export_directory, get_entry_text ("export_directory"), PATH_MAX);
|
strncpy (config->export_directory, get_entry_text ("export_directory"), PATH_MAX - 1);
|
||||||
|
|
||||||
if (!strcmp (safety_sram_directory, SAME_GAME))
|
if (!strcmp (safety_sram_directory, SAME_GAME))
|
||||||
safety_sram_directory[0] = '\0';
|
safety_sram_directory[0] = '\0';
|
||||||
|
|
|
@ -859,7 +859,7 @@ Snes9xWindow::open_movie_dialog (bool readonly)
|
||||||
|
|
||||||
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
|
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
|
||||||
|
|
||||||
snprintf (default_name, PATH_MAX, "%s.smv", def);
|
ssnprintf (default_name, PATH_MAX, "%s.smv", def);
|
||||||
|
|
||||||
dialog = gtk_file_chooser_dialog_new (_("New SNES Movie"),
|
dialog = gtk_file_chooser_dialog_new (_("New SNES Movie"),
|
||||||
GTK_WINDOW (this->window),
|
GTK_WINDOW (this->window),
|
||||||
|
@ -1119,7 +1119,7 @@ Snes9xWindow::save_state_dialog ()
|
||||||
|
|
||||||
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
|
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
|
||||||
|
|
||||||
snprintf (default_name, PATH_MAX, "%s.sst", def);
|
ssnprintf (default_name, PATH_MAX, "%s.sst", def);
|
||||||
|
|
||||||
dialog = gtk_file_chooser_dialog_new (_("Save State"),
|
dialog = gtk_file_chooser_dialog_new (_("Save State"),
|
||||||
GTK_WINDOW (this->window),
|
GTK_WINDOW (this->window),
|
||||||
|
@ -1195,7 +1195,7 @@ Snes9xWindow::save_spc_dialog ()
|
||||||
|
|
||||||
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
|
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
|
||||||
|
|
||||||
snprintf (default_name, PATH_MAX, "%s.spc", def);
|
ssnprintf (default_name, PATH_MAX, "%s.spc", def);
|
||||||
|
|
||||||
dialog = gtk_file_chooser_dialog_new (_("Save SPC file..."),
|
dialog = gtk_file_chooser_dialog_new (_("Save SPC file..."),
|
||||||
GTK_WINDOW (this->window),
|
GTK_WINDOW (this->window),
|
||||||
|
|
|
@ -434,7 +434,7 @@ static int read_movie_extrarominfo (FILE *fd, SMovie *movie)
|
||||||
|
|
||||||
ptr += 3; // zero bytes
|
ptr += 3; // zero bytes
|
||||||
movie->ROMCRC32 = Read32(ptr);
|
movie->ROMCRC32 = Read32(ptr);
|
||||||
strncpy(movie->ROMName, (char *) ptr, 23);
|
strncpy(movie->ROMName, (char *) ptr, 22);
|
||||||
|
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
2
port.h
2
port.h
|
@ -148,6 +148,8 @@ void SetInfoDlgColor(unsigned char, unsigned char, unsigned char);
|
||||||
#endif // __LIBRETRO__
|
#endif // __LIBRETRO__
|
||||||
#endif // __WIN32__
|
#endif // __WIN32__
|
||||||
|
|
||||||
|
#define ssnprintf(dst, size, fmt, ...) if (snprintf (dst, size, fmt, __VA_ARGS__) >= (int) size) dst[size - 1] = '\0';
|
||||||
|
|
||||||
#if defined(__DJGPP) || defined(__WIN32__)
|
#if defined(__DJGPP) || defined(__WIN32__)
|
||||||
#define SLASH_STR "\\"
|
#define SLASH_STR "\\"
|
||||||
#define SLASH_CHAR '\\'
|
#define SLASH_CHAR '\\'
|
||||||
|
|
|
@ -1013,7 +1013,7 @@ void S9xResetSaveTimer (bool8 dontsave)
|
||||||
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], def[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
|
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], def[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
|
||||||
|
|
||||||
_splitpath(Memory.ROMFilename, drive, dir, def, ext);
|
_splitpath(Memory.ROMFilename, drive, dir, def, ext);
|
||||||
snprintf(filename, PATH_MAX + 1, "%s%s%s.%.*s", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, _MAX_EXT - 1, "oops");
|
ssnprintf(filename, PATH_MAX + 1, "%s%s%s.%.*s", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, _MAX_EXT - 1, "oops");
|
||||||
S9xMessage(S9X_INFO, S9X_FREEZE_FILE_INFO, SAVE_INFO_OOPS);
|
S9xMessage(S9X_INFO, S9X_FREEZE_FILE_INFO, SAVE_INFO_OOPS);
|
||||||
S9xFreezeGame(filename);
|
S9xFreezeGame(filename);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue