Changeset - r15141:30f51f1460e5
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2010-05-10 09:50:49
rubidium@openttd.org
(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
1 file changed with 6 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/os/unix/unix.cpp
Show inline comments
 
@@ -92,17 +92,20 @@ bool FiosGetDiskFreeSpace(const char *pa
 
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;
 
}
0 comments (0 inline, 0 general)