From: VMware, Inc <> Date: Mon, 21 May 2012 22:19:56 +0000 (-0700) Subject: Fix File_PathJoin ASSERTs some more X-Git-Tag: 2012.05.21-724730~52 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=427f59fa834be6dc32e5a8bda263af4f081df24b;p=thirdparty%2Fopen-vm-tools.git Fix File_PathJoin ASSERTs some more I think that File_PathJoin's ASSERTs were a bit too aggressive. I believe that the intention was to disallow UNC paths for the tail portion of the path, not to disallow all paths that start with a directory separator. (Allowing a leading directory separator on Linux but not on Windows seems a bit dangerous anyway.) Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/lib/file/fileStandAlone.c b/open-vm-tools/lib/file/fileStandAlone.c index 009f680f8..6b01532d0 100644 --- a/open-vm-tools/lib/file/fileStandAlone.c +++ b/open-vm-tools/lib/file/fileStandAlone.c @@ -320,16 +320,28 @@ File_SplitName(ConstUnicode pathName, // IN: * * File_PathJoin -- * - * Join the dirName and baseName together to create a (full) path but - * don't add a DIRSEPS unless necessary. + * Join the dirName and baseName together to create a (full) path. + * + * This code concatenates two strings together and omits a redundant + * directory separator between the two. It does not treat a fully qualified + * baseName the way one would expect: + * + * File_PathJoin("", "b") -> "/b" + * File_PathJoin("/", "b") -> "/b" + * File_PathJoin("a", "b") -> "a/b" + * File_PathJoin("a/", "b") -> "a/b" + * File_PathJoin("a/////", "b") -> "a/b" + * File_PathJoin("a", "") -> "a/" + * File_PathJoin("a", "/") -> "a/" (only posix) + * File_PathJoin("a", "/b") -> "a/b" (only posix) + * File_PathJoin("a", "/////b") -> "a/b" (only posix) + * File_PathJoin("a/", "/b") -> "a/b" (only posix) + * File_PathJoin("a/////", "/////b") -> "a/b" (only posix) * - * File_PathJoin("a", "b") -> "a/b" - * File_PathJoin("a/", "b") -> "a/b" - * - * Results: + * Results: * The constructed path which must be freed by the caller. * - * Side effects: + * Side effects: * None * *--------------------------------------------------------------------------- @@ -340,15 +352,33 @@ File_PathJoin(ConstUnicode dirName, // IN: ConstUnicode baseName) // IN: { Unicode result; + Unicode newDir = NULL; ASSERT(dirName); ASSERT(baseName); - if (Unicode_EndsWith(dirName, DIRSEPS)) { - result = Unicode_Append(dirName, baseName); - } else { - result = Unicode_Join(dirName, DIRSEPS, baseName, NULL); +#if defined(_WIN32) + ASSERT(!Unicode_StartsWith(baseName, DIRSEPS)); + ASSERT(!Unicode_StartsWith(baseName, "/")); + ASSERT(Unicode_LengthInCodePoints(baseName) < 2 || + Unicode_FindSubstrInRange(baseName, 1, 1, ":", 0, 1) == + UNICODE_INDEX_NOT_FOUND); +#else + /* + * Remove ALL directory separators from baseName begin. + */ + while(Unicode_StartsWith(baseName, DIRSEPS)) { + baseName++; } +#endif + + /* + * Remove ALL directory separators from dirName end. + */ + newDir = File_StripSlashes(dirName); + + result = Unicode_Join(newDir, DIRSEPS, baseName, NULL); + Unicode_Free(newDir); return result; }