• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 6c51adeb71da076c5c40a45e339e06bb4394a86b Mon Sep 17 00:00:00 2001
2From: Eric Vigeant <evigeant@gmail.com>
3Date: Wed, 2 Nov 2022 11:47:09 -0400
4Subject: [PATCH] cur_path: do not add '/' if homedir ends with one
5
6When using SFTP and a path relative to the user home, do not add a
7trailing '/' to the user home dir if it already ends with one.
8
9Closes #9844
10---
11 lib/curl_path.c | 10 +++++++---
12 1 file changed, 7 insertions(+), 3 deletions(-)
13
14--- a/lib/curl_path.c
15+++ b/lib/curl_path.c
16@@ -69,10 +69,14 @@ CURLcode Curl_getworkingpath(struct Curl
17       /* It is referenced to the home directory, so strip the
18          leading '/' */
19       memcpy(real_path, homedir, homelen);
20-      real_path[homelen] = '/';
21-      real_path[homelen + 1] = '\0';
22+      /* Only add a trailing '/' if homedir does not end with one */
23+      if(homelen == 0 || real_path[homelen - 1] != '/') {
24+        real_path[homelen] = '/';
25+        homelen++;
26+        real_path[homelen] = '\0';
27+      }
28       if(working_path_len > 3) {
29-        memcpy(real_path + homelen + 1, working_path + 3,
30+        memcpy(real_path + homelen, working_path + 3,
31                1 + working_path_len -3);
32       }
33     }
34