]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
Fix change_dir() leaving appended slash in curr_dir on failure.
authorWayne Davison <wayne@opencoder.net>
Thu, 4 Jun 2020 19:35:19 +0000 (12:35 -0700)
committerWayne Davison <wayne@opencoder.net>
Thu, 4 Jun 2020 19:35:24 +0000 (12:35 -0700)
util.c

diff --git a/util.c b/util.c
index e1a755651d4c5d198e5ba28927d7db6606dc116a..2c734b7c401fe385554423f9dc0e6d382e298b0c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1116,6 +1116,7 @@ int change_dir(const char *dir, int set_path_only)
                skipped_chdir = set_path_only;
                memcpy(curr_dir, dir, len + 1);
        } else {
+               unsigned int save_dir_len = curr_dir_len;
                if (curr_dir_len + 1 + len >= sizeof curr_dir) {
                        errno = ENAMETOOLONG;
                        return 0;
@@ -1125,6 +1126,7 @@ int change_dir(const char *dir, int set_path_only)
                memcpy(curr_dir + curr_dir_len, dir, len + 1);
 
                if (!set_path_only && chdir(curr_dir)) {
+                       curr_dir_len = save_dir_len;
                        curr_dir[curr_dir_len] = '\0';
                        return 0;
                }