]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
InitiateFileTransferToGuest fails when uploading file to root directory
authorOliver Kurth <okurth@vmware.com>
Wed, 10 Apr 2019 21:14:49 +0000 (14:14 -0700)
committerOliver Kurth <okurth@vmware.com>
Wed, 10 Apr 2019 21:14:49 +0000 (14:14 -0700)
File upload to '/' on Linux fails the directory exists check.
This is caused by the file dirname being an empty string when parsed from the guest file path name per the documented behavior of File_GetPathName.

The caller of File_GetPathName needs to handle the expected empty dirname string when dealing with file path in the root ('/') filesystem on Linux.

Proposed fix is to replace the dirname string with the root path ('/') when:
A. dirname obtained from File_GetPathName call is an empty string AND
B. the original file path name starts with the path separator ('/') on Linux (or *nix like) GOSes

This allows for the directory checks to inspect the root folder before proceedeing with the file transfer.

open-vm-tools/services/plugins/vix/vixTools.c

index 15b0a8bdffe3226f012e266a22d834feb892f563..89947da3fd5f546a8377377e3ff44bdccbb8b1af 100644 (file)
@@ -4980,7 +4980,11 @@ VixToolsInitiateFileTransferToGuest(VixCommandRequestHeader *requestMsg)  // IN
       goto abort;
    }
 
+#ifdef _WIN32
    File_GetPathName(guestPathName, &dirName, &baseName);
+#else
+   File_SplitName(guestPathName, NULL, &dirName, &baseName);
+#endif
    if ((NULL == dirName) || (NULL == baseName)) {
       g_debug("%s: File_GetPathName failed for '%s', dirName='%s', "
               "baseName='%s'.\n", __FUNCTION__, guestPathName,
@@ -4990,6 +4994,19 @@ VixToolsInitiateFileTransferToGuest(VixCommandRequestHeader *requestMsg)  // IN
       goto abort;
    }
 
+/*
+#ifndef _WIN32
+   if ('\0' == *dirName && '/' == *guestPathName) {
+      *
+       * dirName is empty and represents root directory
+       * For *nix like paths, changing dirName to '/'
+       *
+      free(dirName);
+      dirName = Util_SafeStrdup("/");
+   }
+#endif
+*/
+
    if (!File_IsDirectory(dirName)) {
 #ifdef _WIN32
       DWORD sysErr = GetLastError();