]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
Fix some issues with backslashed wildcards in args.
authorWayne Davison <wayne@opencoder.net>
Tue, 9 Aug 2022 01:30:43 +0000 (18:30 -0700)
committerWayne Davison <wayne@opencoder.net>
Tue, 9 Aug 2022 02:26:05 +0000 (19:26 -0700)
exclude.c
options.c

index ca10b094ff38e58a08cf591297cc47c82fa095e2..0dc6c7dd2cbce45ab37a58afc0feb5abe64e74ed 100644 (file)
--- a/exclude.c
+++ b/exclude.c
@@ -319,7 +319,7 @@ void add_implied_include(const char *arg)
        } else if ((cp = strrchr(arg, '/')) != NULL) {
                arg = cp + 1;
                if (*arg == '.' && arg[1] == '\0')
-                   arg++;
+                       arg++;
        }
        arg_len = strlen(arg);
        if (arg_len) {
@@ -347,9 +347,13 @@ void add_implied_include(const char *arg)
                while (*cp) {
                        switch (*cp) {
                          case '\\':
-                               backslash_cnt++;
-                               if (saw_wild)
-                                       *p++ = '\\';
+                               if (cp[1] == ']')
+                                       cp++; /* A \] in a filter might cause a problem w/o wildcards. */
+                               else if (!strchr("*[?", cp[1])) {
+                                       backslash_cnt++;
+                                       if (saw_wild)
+                                               *p++ = '\\';
+                               }
                                *p++ = *cp++;
                                break;
                          case '/':
@@ -377,7 +381,7 @@ void add_implied_include(const char *arg)
                                                implied_filter_list.head = R_rule;
                                                if (DEBUG_GTE(FILTER, 3)) {
                                                        rprintf(FINFO, "[%s] add_implied_include(%s/)\n",
-                                                               who_am_i(), rule->pattern);
+                                                               who_am_i(), R_rule->pattern);
                                                }
                                        }
                                }
@@ -392,6 +396,7 @@ void add_implied_include(const char *arg)
                *p = '\0';
                rule->u.slash_cnt = slash_cnt;
                arg = (const char *)rule->pattern;
+               arg_len = p - arg; /* We recompute it due to backslash weirdness. */
                if (DEBUG_GTE(FILTER, 3))
                        rprintf(FINFO, "[%s] add_implied_include(%s)\n", who_am_i(), rule->pattern);
        }
index 9731a144e973c3558cbb79555872a40f357841f1..a60ff5156926165ce0a9f3a69defe6576816b931 100644 (file)
--- a/options.c
+++ b/options.c
@@ -2521,7 +2521,10 @@ char *safe_arg(const char *opt, const char *arg)
                const char *f = arg;
                char *t = ret + len1;
                while (*f) {
-                       if (strchr(escapes, *f))
+                        if (*f == '\\') {
+                               if (!is_filename_arg || !strchr(WILD_CHARS, f[1]))
+                                       *t++ = '\\';
+                       } else if (strchr(escapes, *f))
                                *t++ = '\\';
                        *t++ = *f++;
                }