From: Wayne Davison Date: Tue, 9 Aug 2022 18:37:37 +0000 (-0700) Subject: Fix handling of daemon module names in file-list verification; convert some while... X-Git-Tag: v3.2.5~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c86763dc382fc6ed6c4c4c461243f51acfc3f226;p=thirdparty%2Frsync.git Fix handling of daemon module names in file-list verification; convert some while loops to for loops. --- diff --git a/exclude.c b/exclude.c index ba5ca5a3..d36a105e 100644 --- a/exclude.c +++ b/exclude.c @@ -316,13 +316,11 @@ static void maybe_add_literal_brackets_rule(filter_rule const *based_on, int arg if (arg_len < 0) arg_len = strlen(arg); - cp = arg; - while (*cp) { + for (cp = arg; *cp; cp++) { if (*cp == '\\' && cp[1]) { cp++; } else if (*cp == '[') cnt++; - cp++; } if (!cnt) return; @@ -331,8 +329,7 @@ static void maybe_add_literal_brackets_rule(filter_rule const *based_on, int arg 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) { + for (cp = arg; *cp; ) { if (*cp == '\\' && cp[1]) { *p++ = *cp++; } else if (*cp == '[') @@ -373,7 +370,7 @@ void free_implied_include_partial_string() /* 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) +void add_implied_include(const char *arg, int skip_daemon_module) { filter_rule *rule; int arg_len, saw_wild = 0, saw_live_open_brkt = 0, backslash_cnt = 0; @@ -390,6 +387,12 @@ void add_implied_include(const char *arg) partial_string_len = 0; arg = partial_string_buf; } + if (skip_daemon_module) { + if ((cp = strchr(arg, '/')) != NULL) + arg = cp + 1; + else + arg = ""; + } if (relative_paths) { if ((cp = strstr(arg, "/./")) != NULL) arg = cp + 3; @@ -402,11 +405,8 @@ void add_implied_include(const char *arg) if (arg_len) { if (strpbrk(arg, "*[?")) { /* We need to add room to escape backslashes if wildcard chars are present. */ - cp = arg; - while ((cp = strchr(cp, '\\')) != NULL) { + for (cp = arg; (cp = strchr(cp, '\\')) != NULL; cp++) arg_len++; - cp++; - } saw_wild = 1; } arg_len++; /* Leave room for the prefixed slash */ @@ -420,8 +420,7 @@ void add_implied_include(const char *arg) rule->rflags = FILTRULE_INCLUDE + (saw_wild ? FILTRULE_WILD : 0); p = rule->pattern = new_array(char, arg_len + 1); *p++ = '/'; - cp = arg; - while (*cp) { + for (cp = arg; *cp; ) { switch (*cp) { case '\\': if (cp[1] == ']') @@ -498,8 +497,7 @@ void add_implied_include(const char *arg) if (!saw_wild && backslash_cnt) { /* We are appending a wildcard, so now the backslashes need to be escaped. */ p = rule->pattern = new_array(char, arg_len + backslash_cnt + 3 + 1); - cp = arg; - while (*cp) { + for (cp = arg; *cp; ) { if (*cp == '\\') *p++ = '\\'; *p++ = *cp++; diff --git a/io.c b/io.c index 7111878a..3f605d74 100644 --- a/io.c +++ b/io.c @@ -420,7 +420,7 @@ static void forward_filesfrom_data(void) while (s != eob) { if (*s++ == '\0') { ff_xb.len = s - sob - 1; - add_implied_include(sob); + add_implied_include(sob, 0); if (iconvbufs(ic_send, &ff_xb, &iobuf.out, flags) < 0) exit_cleanup(RERR_PROTOCOL); /* impossible? */ write_buf(iobuf.out_fd, s-1, 1); /* Send the '\0'. */ @@ -457,7 +457,7 @@ static void forward_filesfrom_data(void) /* Eliminate any multi-'\0' runs. */ while (f != eob) { if (!(*t++ = *f++)) { - add_implied_include(cur); + add_implied_include(cur, 0); cur = t; while (f != eob && *f == '\0') f++; diff --git a/main.c b/main.c index fa263d27..6721ceb7 100644 --- a/main.c +++ b/main.c @@ -1504,7 +1504,7 @@ static int start_client(int argc, char *argv[]) int dummy_port = rsync_port; int i; if (filesfrom_fd < 0) - add_implied_include(remote_argv[0]); + add_implied_include(remote_argv[0], daemon_connection); /* For remote source, any extra source args must have either * the same hostname or an empty hostname. */ for (i = 1; i < remote_argc; i++) { @@ -1528,7 +1528,7 @@ static int start_client(int argc, char *argv[]) if (!rsync_port && !*arg) /* Turn an empty arg into a dot dir. */ arg = "."; remote_argv[i] = arg; - add_implied_include(arg); + add_implied_include(arg, daemon_connection); } }