]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cur_path: do not add '/' if homedir ends with one
authorEric Vigeant <evigeant@gmail.com>
Wed, 2 Nov 2022 15:47:09 +0000 (11:47 -0400)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 3 Nov 2022 08:31:43 +0000 (09:31 +0100)
When using SFTP and a path relative to the user home, do not add a
trailing '/' to the user home dir if it already ends with one.

Closes #9844

lib/curl_path.c

index 27ff96d1fc5580f2cdb011524de9a1328eefddef..f00e3ee74dcebc7a21a0e84cd132c223d9e8ba1b 100644 (file)
@@ -71,10 +71,14 @@ CURLcode Curl_getworkingpath(struct Curl_easy *data,
       /* It is referenced to the home directory, so strip the
          leading '/' */
       memcpy(real_path, homedir, homelen);
-      real_path[homelen] = '/';
-      real_path[homelen + 1] = '\0';
+      /* Only add a trailing '/' if homedir does not end with one */
+      if(homelen == 0 || real_path[homelen - 1] != '/') {
+        real_path[homelen] = '/';
+        homelen++;
+        real_path[homelen] = '\0';
+      }
       if(working_path_len > 3) {
-        memcpy(real_path + homelen + 1, working_path + 3,
+        memcpy(real_path + homelen, working_path + 3,
                1 + working_path_len -3);
       }
     }