From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:55 +0000 (-0700) Subject: lib/file: File_ReplaceExtension fails in the root directory X-Git-Tag: stable-10.2.0~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fbc7387c1edb0bc619cc05fecb84030809c38867;p=thirdparty%2Fopen-vm-tools.git lib/file: File_ReplaceExtension fails in the root directory On Linux, File_ReplaceExtension returns an incorrect path name for a file in the root directory. The code, as written, doesn't differentiate "test.txt" from "/test.txt". Fix this. --- diff --git a/open-vm-tools/lib/file/fileStandAlone.c b/open-vm-tools/lib/file/fileStandAlone.c index f67fd5690..d29e08aa5 100644 --- a/open-vm-tools/lib/file/fileStandAlone.c +++ b/open-vm-tools/lib/file/fileStandAlone.c @@ -730,8 +730,8 @@ File_ReplaceExtension(const char *pathName, // IN: va_list arguments; UnicodeIndex index; - ASSERT(pathName); - ASSERT(newExtension); + ASSERT(pathName != NULL); + ASSERT(newExtension != NULL); ASSERT(*newExtension == '.'); File_GetPathName(pathName, &path, &base); @@ -775,7 +775,16 @@ File_ReplaceExtension(const char *pathName, // IN: } if (Unicode_IsEmpty(path)) { - result = Unicode_Append(base, newExtension); + /* + * The pathName may be for a file in the CWD (e.g. "file.txt") or it + * could be in the POSIX root directory (e.g. "/file.txt"). + */ + + if (File_IsFullPath(pathName)) { + result = Unicode_Join(DIRSEPS, base, newExtension, NULL); + } else { + result = Unicode_Append(base, newExtension); + } } else { result = Unicode_Join(path, DIRSEPS, base, newExtension, NULL); }