From 7190d27a586ee1a4be4a550833f5ec91fca5402e Mon Sep 17 00:00:00 2001 From: /dev/humancontroller Date: Sat, 12 Jul 2014 22:06:26 +0200 Subject: fix crashing when an fs_*path is relative, but does not have an initial "." component (eg., fs_homepath = "dir1/dir2"), or when a path contains multiple consecutive separators (eg. "dir//file") --- src/qcommon/files.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/qcommon') diff --git a/src/qcommon/files.c b/src/qcommon/files.c index 4edf0318..5ab6e980 100644 --- a/src/qcommon/files.c +++ b/src/qcommon/files.c @@ -509,13 +509,12 @@ qboolean FS_CreatePath (char *OSPath) { Q_strncpyz( path, OSPath, sizeof( path ) ); FS_ReplaceSeparators( path ); - // Skip creation of the root directory as it will always be there - ofs = strchr( path, PATH_SEP ); - if ( ofs != NULL ) { + ofs = path; + while ( *ofs == PATH_SEP ) { ofs++; } - for (; ofs != NULL && *ofs ; ofs++) { + for ( ; *ofs ; ofs++) { if (*ofs == PATH_SEP) { // create the directory *ofs = 0; @@ -524,6 +523,9 @@ qboolean FS_CreatePath (char *OSPath) { path ); } *ofs = PATH_SEP; + while ( *(ofs + 1) == PATH_SEP ) { + ofs++; + } } } -- cgit