diff options
author | rubidium <rubidium@openttd.org> | 2010-05-10 09:50:49 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-05-10 09:50:49 +0000 |
commit | 6d94dd10dd69bcd459d84e8c99423c16edaeecb1 (patch) | |
tree | 0fe18a1c82053779d48868bdbef38ef72966e1e8 | |
parent | 08919d2747b1f6fc9ed702a67a83a3c5867a1188 (diff) | |
download | openttd-6d94dd10dd69bcd459d84e8c99423c16edaeecb1.tar.xz |
(svn r19780) -Fix [FS#3807]: make sure that when checking whether a path + filename are valid the whole string can be constructed within an array of length MAX_PATH. If not, the name is too long and is deemed invalid
-rw-r--r-- | src/os/unix/unix.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/os/unix/unix.cpp b/src/os/unix/unix.cpp index a9b81e62c..44b27bbad 100644 --- a/src/os/unix/unix.cpp +++ b/src/os/unix/unix.cpp @@ -92,17 +92,20 @@ bool FiosGetDiskFreeSpace(const char *path, uint64 *tot) bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb) { char filename[MAX_PATH]; - + int res; #if defined(__MORPHOS__) || defined(__AMIGAOS__) /* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */ if (FiosIsRoot(path)) { - snprintf(filename, lengthof(filename), "%s:%s", path, ent->d_name); + res = snprintf(filename, lengthof(filename), "%s:%s", path, ent->d_name); } else // XXX - only next line! #else assert(path[strlen(path) - 1] == PATHSEPCHAR); if (strlen(path) > 2) assert(path[strlen(path) - 2] != PATHSEPCHAR); #endif - snprintf(filename, lengthof(filename), "%s%s", path, ent->d_name); + res = snprintf(filename, lengthof(filename), "%s%s", path, ent->d_name); + + /* Could we fully concatenate the path and filename? */ + if (res >= (int)lengthof(filename) || res < 0) return false; return stat(filename, sb) == 0; } |