From 9fd6b1009e148ae5cd110ee3682650e45c0a7b6c Mon Sep 17 00:00:00 2001 From: peter1138 Date: Tue, 31 Jan 2006 12:08:49 +0000 Subject: [PATCH] (svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?' --- os2.c | 4 ++++ unix.c | 4 ++++ win32.c | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/os2.c b/os2.c index 6aa5a61ca6..c2fd448f37 100644 --- a/os2.c +++ b/os2.c @@ -109,6 +109,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode) fios->mtime = 0; ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", dirent->d_name); + str_validate(fios->title); } } closedir(dir); @@ -150,6 +151,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode) *t = '\0'; // strip extension ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); + str_validate(fios->title); } else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) { if (strcasecmp(t, ".ss1") == 0 || strcasecmp(t, ".sv1") == 0 || @@ -236,6 +238,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode) fios->mtime = 0; ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", dirent->d_name); + str_validate(fios->title); } } closedir(dir); @@ -276,6 +279,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode) *t = '\0'; // strip extension ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); + str_validate(fios->title); } else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || mode == SLD_NEW_GAME) { if (strcasecmp(t, ".sv0") == 0 || diff --git a/unix.c b/unix.c index 7e23aca005..192337ef38 100644 --- a/unix.c +++ b/unix.c @@ -121,6 +121,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode) ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); snprintf(fios->title, lengthof(fios->title), "%s/ (Directory)", dirent->d_name); + str_validate(fios->title); } } closedir(dir); @@ -163,6 +164,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode) *t = '\0'; // strip extension ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); + str_validate(fios->title); } else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) { if (strcasecmp(t, ".ss1") == 0 || strcasecmp(t, ".sv1") == 0 || @@ -222,6 +224,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode) fios->mtime = 0; ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); snprintf(fios->title, lengthof(fios->title), "%s/ (Directory)", dirent->d_name); + str_validate(fios->title); } } closedir(dir); @@ -262,6 +265,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode) *t = '\0'; // strip extension ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); + str_validate(fios->title); } else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || mode == SLD_NEW_GAME) { if (strcasecmp(t, ".sv0") == 0 || diff --git a/win32.c b/win32.c index 409bb8f717..05218884f3 100644 --- a/win32.c +++ b/win32.c @@ -686,6 +686,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode) fios->mtime = 0; ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", fd.cFileName); + str_validate(fios->title); } } while (FindNextFile(h, &fd)); FindClose(h); @@ -726,6 +727,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode) *t = '\0'; // strip extension ttd_strlcpy(fios->title, fd.cFileName, lengthof(fios->title)); + str_validate(fios->title); } else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) { if (strcasecmp(t, ".ss1") == 0 || strcasecmp(t, ".sv1") == 0 || @@ -800,6 +802,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode) fios->mtime = 0; ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", fd.cFileName); + str_validate(fios->title); } } while (FindNextFile(h, &fd)); FindClose(h); @@ -839,6 +842,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode) *t = '\0'; // strip extension ttd_strlcpy(fios->title, fd.cFileName, lengthof(fios->title)); + str_validate(fios->title); } else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || mode == SLD_NEW_GAME) { if (strcasecmp(t, ".sv0") == 0 ||