# HG changeset patch # User peter1138 # Date 1138709329 0 # Node ID ce57a148333e9fdeeb3592f14643bf73ca7316e0 # Parent e598b646985dd4eb7df0a52e2420a9b8170d818e (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 '?' diff -r e598b646985d -r ce57a148333e os2.c --- a/os2.c Tue Jan 31 06:53:32 2006 +0000 +++ b/os2.c Tue Jan 31 12:08:49 2006 +0000 @@ -109,6 +109,7 @@ 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 @@ *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 @@ 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 @@ *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 -r e598b646985d -r ce57a148333e unix.c --- a/unix.c Tue Jan 31 06:53:32 2006 +0000 +++ b/unix.c Tue Jan 31 12:08:49 2006 +0000 @@ -121,6 +121,7 @@ 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 @@ *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 @@ 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 @@ *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 -r e598b646985d -r ce57a148333e win32.c --- a/win32.c Tue Jan 31 06:53:32 2006 +0000 +++ b/win32.c Tue Jan 31 12:08:49 2006 +0000 @@ -686,6 +686,7 @@ 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 @@ *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 @@ 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 @@ *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 ||