]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Hgfs Fuse Client: fix symlinks
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:22:47 +0000 (11:22 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:22:47 +0000 (11:22 -0700)
 Symlinks were not being handled correctly for some cases.

 The symlink creation call tried to make the target an absolute path which
 it should not do. Only the source is passed as the absolute path which
 is created and links to the target which can be relative or absolute but
 is dependent on what the user passes.

 The readlink was broken and incorrectly creating a target name to pass
 to the FUSE library.
 This was obvious when alternative mount points are used
    e.g. .host:/Users -> /Users
 instead of
    .host:/ /mnt/hgfs

 This was discovered when used in the containers environment with docker.
 However, it is a standard option for HGFS client usage in any hosted product.

open-vm-tools/vmhgfs-fuse/main.c

index db899ca214bf5968263ca54c782fc00503b6cb89..241ce68a71c37bb00d21a9b6de98f127821addf7 100644 (file)
@@ -333,9 +333,10 @@ hgfs_readlink(const char *path, //IN: path to a file
       goto exit;
    }
 
-   if (size >= strlen(attr->fileName)) {
-      Str_Strcpy(buf, attr->fileName + gState->basePathLen,
-                 strlen(attr->fileName) + 1 - gState->basePathLen);
+   if (size > strlen(attr->fileName)) {
+      Str_Strcpy(buf, attr->fileName,
+                 strlen(attr->fileName) + 1);
+      LOG(4, ("ReadLink: link target name = %s\n", buf));
    } else {
       res = -ENOBUFS;
    }
@@ -559,29 +560,24 @@ exit:
  */
 
 static int
-hgfs_symlink(const char *from,      //IN: from path
-             const char *to)        //IN: to path
+hgfs_symlink(const char *symname,   //IN: symname target
+             const char *source)    //IN: source name
 {
-   char *absfrom = NULL;
-   char *absto = NULL;
+   char *absSource = NULL;
    int res;
 
-   LOG(4, ("Entry(from = %s, to = %s)\n", from, to));
-   res = getAbsPath(from, &absfrom);
-   if (res < 0) {
-      goto exit;
-   }
-   res = getAbsPath(to, &absto);
+   LOG(4, ("Entry(from = %s, to = %s)\n", symname, source));
+   res = getAbsPath(source, &absSource);
    if (res < 0) {
       goto exit;
    }
 
-   res = HgfsSymlink(absto, absfrom);
+   LOG(4, ("symname = %s, abs source = %s)\n", symname, absSource));
+   res = HgfsSymlink(absSource, symname);
 
 exit:
    LOG(4, ("Exit(%d)\n", res));
-   freeAbsPath(absfrom);
-   freeAbsPath(absto);
+   freeAbsPath(absSource);
    return res;
 }