]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/file: File_ReplaceExtension fails in the root directory
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:55 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:55 +0000 (11:23 -0700)
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.

open-vm-tools/lib/file/fileStandAlone.c

index f67fd56903bb1016eebdc74b8d6f2194f7368494..d29e08aa521cee05a24d12886d73ebc374f28d63 100644 (file)
@@ -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);
    }