[SCM] The rsync repository. - branch master updated

Rsync CVS commit messages rsync-cvs at lists.samba.org
Tue Aug 9 03:09:44 UTC 2022


The branch, master has been updated
       via  9e2921fc A fix for the zlib fix.
       via  80d8f7c7 Handle a "[foo]" arg matching the literal wildcards.
       via  38e1b075 Fix some issues with backslashed wildcards in args.
      from  d659610a Handle a trailing "/." at the end of a source arg.

https://git.samba.org/?p=rsync.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 9e2921fce8c518e370c324407d35bc83ba12f2d5
Author: Wayne Davison <wayne at opencoder.net>
Date:   Mon Aug 8 20:05:10 2022 -0700

    A fix for the zlib fix.

commit 80d8f7c7cbb062f4ddab47eecb0a2253bb908a82
Author: Wayne Davison <wayne at opencoder.net>
Date:   Mon Aug 8 19:31:36 2022 -0700

    Handle a "[foo]" arg matching the literal wildcards.

commit 38e1b075b49664181a6b1727219b404debec035e
Author: Wayne Davison <wayne at opencoder.net>
Date:   Mon Aug 8 18:30:43 2022 -0700

    Fix some issues with backslashed wildcards in args.

-----------------------------------------------------------------------

Summary of changes:
 exclude.c      | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
 options.c      |  5 +++-
 zlib/inflate.c |  4 ++--
 3 files changed, 75 insertions(+), 10 deletions(-)


Changeset truncated at 500 lines:

diff --git a/exclude.c b/exclude.c
index ca10b094..d811dd1f 100644
--- a/exclude.c
+++ b/exclude.c
@@ -302,12 +302,59 @@ static void add_rule(filter_rule_list *listp, const char *pat, unsigned int pat_
 	}
 }
 
+/* If the wildcards failed, the remote shell might give us a file matching the literal
+ * wildcards.  Since "*" & "?" already match themselves, this just needs to deal with
+ * failed "[foo]" idioms.
+ */
+static void maybe_add_literal_brackets_rule(filter_rule const *based_on, int arg_len)
+{
+	filter_rule *rule;
+	const char *arg = based_on->pattern, *cp;
+	char *p;
+	int cnt = 0;
+
+	if (arg_len < 0)
+		arg_len = strlen(arg);
+
+	cp = arg;
+	while (*cp) {
+		if (*cp == '\\' && cp[1]) {
+			cp++;
+		} else if (*cp == '[')
+			cnt++;
+		cp++;
+	}
+	if (!cnt)
+		return;
+
+	rule = new0(filter_rule);
+	rule->rflags = based_on->rflags;
+	rule->u.slash_cnt = based_on->u.slash_cnt;
+	p = rule->pattern = new_array(char, arg_len + cnt + 1);
+	cp = arg;
+	while (*cp) {
+		if (*cp == '\\' && cp[1]) {
+			*p++ = *cp++;
+		} else if (*cp == '[')
+			*p++ = '\\';
+		*p++ = *cp++;
+	}
+	*p++ = '\0';
+
+	rule->next = implied_filter_list.head;
+	implied_filter_list.head = rule;
+	if (DEBUG_GTE(FILTER, 3)) {
+		rprintf(FINFO, "[%s] add_implied_include(%s%s)\n", who_am_i(), rule->pattern,
+			rule->rflags & FILTRULE_DIRECTORY ? "/" : "");
+	}
+}
+
 /* Each arg the client sends to the remote sender turns into an implied include
  * that the receiver uses to validate the file list from the sender. */
 void add_implied_include(const char *arg)
 {
 	filter_rule *rule;
-	int arg_len, saw_wild = 0, backslash_cnt = 0;
+	int arg_len, saw_wild = 0, saw_live_open_brkt = 0, backslash_cnt = 0;
 	int slash_cnt = 1; /* We know we're adding a leading slash. */
 	const char *cp;
 	char *p;
@@ -319,7 +366,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 +394,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,13 +428,19 @@ 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);
 						}
+						if (saw_live_open_brkt)
+							maybe_add_literal_brackets_rule(R_rule, -1);
 					}
 				}
 				slash_cnt++;
 				*p++ = *cp++;
 				break;
+			  case '[':
+				saw_live_open_brkt = 1;
+				*p++ = *cp++;
+				break;
 			  default:
 				*p++ = *cp++;
 				break;
@@ -391,9 +448,12 @@ void add_implied_include(const char *arg)
 		}
 		*p = '\0';
 		rule->u.slash_cnt = slash_cnt;
-		arg = (const char *)rule->pattern;
+		arg = 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);
+		if (saw_live_open_brkt)
+			maybe_add_literal_brackets_rule(rule, arg_len);
 	}
 
 	if (recurse || xfer_dirs) {
@@ -430,6 +490,8 @@ void add_implied_include(const char *arg)
 		implied_filter_list.head = rule;
 		if (DEBUG_GTE(FILTER, 3))
 			rprintf(FINFO, "[%s] add_implied_include(%s)\n", who_am_i(), rule->pattern);
+		if (saw_live_open_brkt)
+			maybe_add_literal_brackets_rule(rule, p - 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++;
 		}
diff --git a/zlib/inflate.c b/zlib/inflate.c
index d15132ea..e9840b67 100644
--- a/zlib/inflate.c
+++ b/zlib/inflate.c
@@ -739,10 +739,10 @@ int flush;
                 copy = state->length;
                 if (copy > have) copy = have;
                 if (copy) {
-                    len = state->head->extra_len - state->length;
                     if (state->head != Z_NULL &&
                         state->head->extra != Z_NULL &&
-                        len < state->head->extra_max) {
+                        (len = state->head->extra_len - state->length) <
+                            state->head->extra_max) {
                         zmemcpy(state->head->extra + len, next,
                                 len + copy > state->head->extra_max ?
                                 state->head->extra_max - len : copy);


-- 
The rsync repository.



More information about the rsync-cvs mailing list