From: Wayne Davison Date: Tue, 9 Aug 2022 01:30:43 +0000 (-0700) Subject: Fix some issues with backslashed wildcards in args. X-Git-Tag: v3.2.5pre2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38e1b075b49664181a6b1727219b404debec035e;p=thirdparty%2Frsync.git Fix some issues with backslashed wildcards in args. --- diff --git a/exclude.c b/exclude.c index ca10b094..0dc6c7dd 100644 --- 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); } diff --git a/options.c b/options.c index 9731a144..a60ff515 100644 --- 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++; }