From: Wayne Davison Date: Tue, 3 Aug 2004 17:18:14 +0000 (+0000) Subject: - Fixed a couple problems with the daemon's path-sanitizing. X-Git-Url: https://mattmccutchen.net/rsync/rsync-patches.git/commitdiff_plain/045caa90dd6358050a58177254c9bb566f7bbe60 - Fixed a couple problems with the daemon's path-sanitizing. - Avoid a useless "./" prefix on the exclude filenames. --- diff --git a/filter.diff b/filter.diff index 6d640a2..ba553ca 100644 --- a/filter.diff +++ b/filter.diff @@ -31,13 +31,19 @@ contained a slash. ..wayne.. --- orig/exclude.c 2004-05-22 19:30:03 -+++ exclude.c 2004-07-03 20:21:27 -@@ -30,13 +30,59 @@ extern int verbose; ++++ exclude.c 2004-08-03 17:06:22 +@@ -27,16 +27,65 @@ + #include "rsync.h" + + extern int verbose; ++extern int am_sender; extern int eol_nulls; extern int list_only; extern int recurse; +extern int io_error; +extern int module_id; ++extern int delete_mode; ++extern int delete_excluded; +extern int inherit_exclude_levels; +extern int sanitize_paths; @@ -93,7 +99,7 @@ contained a slash. /** Build an exclude structure given an exclude pattern. */ static void make_exclude(struct exclude_list_struct *listp, const char *pat, -@@ -46,6 +92,24 @@ static void make_exclude(struct exclude_ +@@ -46,6 +95,24 @@ static void make_exclude(struct exclude_ const char *cp; unsigned int ex_len; @@ -118,7 +124,7 @@ contained a slash. ret = new(struct exclude_struct); if (!ret) out_of_memory("make_exclude"); -@@ -81,14 +145,36 @@ static void make_exclude(struct exclude_ +@@ -81,14 +148,36 @@ static void make_exclude(struct exclude_ mflags |= MATCHFLG_DIRECTORY; } @@ -159,7 +165,7 @@ contained a slash. listp->tail->next = ret; listp->tail = ret; } -@@ -96,22 +182,150 @@ static void make_exclude(struct exclude_ +@@ -96,22 +185,154 @@ static void make_exclude(struct exclude_ static void free_exclude(struct exclude_struct *ex) { @@ -205,7 +211,9 @@ contained a slash. + limit = 0; + fname[len] = '\0'; + if (*fname == '/') -+ strcpy(path, fname); ++ strcpy(path, fname); /* safe */ ++ else if (len == 2 && *fname == '.' && fname[1] == '/') ++ len = strlcpy(path, curr_dir, sizeof path); + else + len = pathjoin(path, sizeof path, curr_dir, fname); + @@ -237,6 +245,8 @@ contained a slash. + * specified with a relative path by saving off the current dir. */ + memcpy(dirbuf, fname, offset); + dirbuf_offset = offset; ++ if (dirbuf_offset == 2 && *dirbuf == '.') ++ dirbuf_offset = 0; + + if (!(push = new_array(struct mergelist_save_struct, 1))) + out_of_memory("push_local_excludes"); @@ -316,7 +326,7 @@ contained a slash. static int check_one_exclude(char *name, struct exclude_struct *ex, int name_is_dir) { -@@ -122,7 +336,7 @@ static int check_one_exclude(char *name, +@@ -122,7 +343,7 @@ static int check_one_exclude(char *name, /* If the pattern does not have any slashes AND it does not have * a "**" (which could match a slash), then we just match the * name portion of the path. */ @@ -325,7 +335,17 @@ contained a slash. if ((p = strrchr(name,'/')) != NULL) name = p+1; } -@@ -148,9 +362,9 @@ static int check_one_exclude(char *name, +@@ -133,7 +354,8 @@ static int check_one_exclude(char *name, + name = full_name; + } + +- if (!name[0]) return 0; ++ if (!name[0]) ++ return 0; + + if (ex->match_flags & MATCHFLG_DIRECTORY && !name_is_dir) + return 0; +@@ -148,9 +370,9 @@ static int check_one_exclude(char *name, if (ex->match_flags & MATCHFLG_WILD) { /* A non-anchored match with an infix slash and no "**" * needs to match the last slash_cnt+1 name elements. */ @@ -337,7 +357,7 @@ contained a slash. for (p = name + strlen(name) - 1; p >= name; p--) { if (*p == '/' && !--cnt) break; -@@ -221,6 +435,13 @@ int check_exclude(struct exclude_list_st +@@ -221,6 +443,13 @@ int check_exclude(struct exclude_list_st struct exclude_struct *ent; for (ent = listp->head; ent; ent = ent->next) { @@ -351,7 +371,7 @@ contained a slash. if (check_one_exclude(name, ent, name_is_dir)) { report_exclude_result(name, ent, name_is_dir, listp->debug_type); -@@ -253,11 +474,16 @@ static const char *get_exclude_tok(const +@@ -253,11 +482,16 @@ static const char *get_exclude_tok(const p = (const char *)s; } @@ -370,7 +390,15 @@ contained a slash. s += 2; } else if (xflags & XFLG_DEF_INCLUDE) mflags |= MATCHFLG_INCLUDE; -@@ -306,11 +532,54 @@ void add_exclude(struct exclude_list_str +@@ -292,6 +526,7 @@ void add_exclude(struct exclude_list_str + cp = pattern; + pat_len = 0; + while (1) { ++ /* Remember that the returned string is NOT '\0' terminated! */ + cp = get_exclude_tok(cp + pat_len, &pat_len, &mflags, xflags); + if (!pat_len) + break; +@@ -306,11 +541,57 @@ void add_exclude(struct exclude_list_str continue; } @@ -381,6 +409,7 @@ contained a slash. + "merge filename too long: %s\n", cp); + continue; + } ++ /* We need a null-terminated version of the filename. */ + strlcpy(name, cp, pat_len+1); + if (!(xflags & XFLG_PERDIR_MERGE) + && (inherit_exclude_levels == -1 @@ -398,15 +427,17 @@ contained a slash. + dirbuf[dirbuf_offset] = '\0'; + sanitize_path(name, dirbuf); + } -+ if (strlcpy(dirbuf + dirbuf_offset, ++ if (!dirbuf_offset) ++ cp = name; ++ else if (strlcpy(dirbuf + dirbuf_offset, + name, MAXPATHLEN - dirbuf_offset) + >= MAXPATHLEN - dirbuf_offset) { + rprintf(FERROR, + "merge filename too long: %s...\n", + dirbuf); + continue; -+ } -+ cp = dirbuf; ++ } else ++ cp = dirbuf; + } + add_exclude_file(listp, cp, + xflags | XFLG_FATAL_ERRORS); @@ -426,7 +457,7 @@ contained a slash. mflags & MATCHFLG_INCLUDE ? "in" : "ex"); } } -@@ -343,6 +612,11 @@ void add_exclude_file(struct exclude_lis +@@ -343,6 +624,11 @@ void add_exclude_file(struct exclude_lis return; } @@ -438,7 +469,7 @@ contained a slash. while (1) { char *s = line; int ch, overflow = 0; -@@ -402,7 +676,11 @@ void send_exclude_list(int f) +@@ -402,7 +688,11 @@ void send_exclude_list(int f) if (ent->match_flags & MATCHFLG_INCLUDE) { write_int(f, l + 2); write_buf(f, "+ ", 2); @@ -451,7 +482,21 @@ contained a slash. write_int(f, l + 2); write_buf(f, "- ", 2); } else -@@ -443,6 +721,7 @@ void add_cvs_excludes(void) +@@ -411,6 +701,13 @@ void send_exclude_list(int f) + } + + write_int(f, 0); ++ ++ /* If we're the receiver and we don't need the excludes, dump them. */ ++ if (!am_sender && (!delete_mode || delete_excluded)) { ++ clear_exclude_list(&exclude_list); ++ inherit_exclude_levels = 0; ++ mergelist_cnt = 0; ++ } + } + + +@@ -443,6 +740,7 @@ void add_cvs_excludes(void) char fname[MAXPATHLEN]; char *p; @@ -459,8 +504,8 @@ contained a slash. add_exclude(&exclude_list, default_cvsignore, XFLG_WORD_SPLIT | XFLG_WORDS_ONLY); ---- orig/flist.c 2004-07-15 02:21:10 -+++ flist.c 2004-07-03 20:21:27 +--- orig/flist.c 2004-07-17 15:20:05 ++++ flist.c 2004-08-03 17:14:17 @@ -39,8 +39,6 @@ extern int module_id; extern int ignore_errors; extern int numeric_ids; @@ -531,7 +576,7 @@ contained a slash. char *p; d = opendir(dir); -@@ -996,19 +982,13 @@ static void send_directory(int f, struct +@@ -996,18 +982,13 @@ static void send_directory(int f, struct offset++; } @@ -546,17 +591,18 @@ contained a slash. - "cannot cvs-exclude in long-named directory %s\n", - full_fname(fname)); - } +- } + if (inherit_exclude_levels > 0) { + pre_inherit_files(fname, offset); + inherit_exclude_levels = 0; - } - -+ save_excludes = push_local_excludes(fname, offset); ++ } else if (inherit_exclude_levels < -1) ++ inherit_exclude_levels = -1; + ++ save_excludes = push_local_excludes(fname, offset); + for (errno = 0, di = readdir(d); di; errno = 0, di = readdir(d)) { char *dname = d_name(di); - if (dname[0] == '.' && (dname[1] == '\0' -@@ -1028,6 +1008,8 @@ static void send_directory(int f, struct +@@ -1028,6 +1009,8 @@ static void send_directory(int f, struct rsyserr(FERROR, errno, "readdir(%s)", dir); } @@ -565,9 +611,9 @@ contained a slash. closedir(d); } ---- orig/options.c 2004-07-16 20:07:22 -+++ options.c 2004-07-03 20:21:27 -@@ -50,6 +50,7 @@ int preserve_gid = 0; +--- orig/options.c 2004-08-03 15:41:32 ++++ options.c 2004-08-03 15:41:39 +@@ -51,6 +51,7 @@ int preserve_gid = 0; int preserve_times = 0; int update_only = 0; int cvs_exclude = 0; @@ -575,7 +621,7 @@ contained a slash. int dry_run = 0; int local_server = 0; int ignore_times = 0; -@@ -315,7 +316,7 @@ void usage(enum logcode F) +@@ -319,7 +320,7 @@ void usage(enum logcode F) enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM, OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST, @@ -584,7 +630,7 @@ contained a slash. OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT, OPT_REFUSED_BASE = 9000}; -@@ -340,6 +341,7 @@ static struct poptOption long_options[] +@@ -344,6 +345,7 @@ static struct poptOption long_options[] {"include", 0, POPT_ARG_STRING, 0, OPT_INCLUDE, 0, 0 }, {"exclude-from", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE_FROM, 0, 0 }, {"include-from", 0, POPT_ARG_STRING, 0, OPT_INCLUDE_FROM, 0, 0 }, @@ -592,7 +638,7 @@ contained a slash. {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks, 0, 0, 0 }, {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 }, {"backup", 'b', POPT_ARG_NONE, &make_backups, 0, 0, 0 }, -@@ -549,6 +551,31 @@ int parse_arguments(int *argc, const cha +@@ -566,6 +568,31 @@ int parse_arguments(int *argc, const cha XFLG_FATAL_ERRORS | XFLG_DEF_INCLUDE); break; @@ -624,17 +670,7 @@ contained a slash. case 'h': usage(FINFO); exit_cleanup(0); -@@ -805,6 +832,9 @@ int parse_arguments(int *argc, const cha - } - } - -+ if (inherit_exclude_levels < 0) -+ inherit_exclude_levels = -1; -+ - return 1; - } - -@@ -906,6 +936,12 @@ void server_options(char **args,int *arg +@@ -969,6 +996,12 @@ void server_options(char **args,int *arg if (x != 1) args[ac++] = argstr; @@ -647,7 +683,7 @@ contained a slash. if (block_size) { if (asprintf(&arg, "-B%u", block_size) < 0) goto oom; ---- orig/rsync.h 2004-07-16 20:07:23 +--- orig/rsync.h 2004-08-03 15:41:32 +++ rsync.h 2004-07-03 20:21:27 @@ -108,6 +108,7 @@ #define XFLG_DEF_INCLUDE (1<<1) @@ -657,7 +693,7 @@ contained a slash. #define PERMS_REPORT (1<<0) #define PERMS_SKIP_MTIME (1<<1) -@@ -498,11 +499,16 @@ struct map_struct { +@@ -499,11 +500,16 @@ struct map_struct { #define MATCHFLG_INCLUDE (1<<4) /* this is an include, not an exclude */ #define MATCHFLG_DIRECTORY (1<<5) /* this matches only directories */ #define MATCHFLG_CLEAR_LIST (1<<6) /* this item is the "!" token */ @@ -675,9 +711,9 @@ contained a slash. }; struct exclude_list_struct { ---- orig/rsync.yo 2004-07-16 20:07:23 -+++ rsync.yo 2004-07-03 20:21:27 -@@ -333,6 +333,7 @@ verb( +--- orig/rsync.yo 2004-08-03 15:34:32 ++++ rsync.yo 2004-08-03 15:34:44 +@@ -334,6 +334,7 @@ verb( --exclude-from=FILE exclude patterns listed in FILE --include=PATTERN don't exclude files matching PATTERN --include-from=FILE don't exclude patterns listed in FILE @@ -685,7 +721,7 @@ contained a slash. --files-from=FILE read FILE for list of source-file names -0 --from0 all file lists are delimited by nulls --version print version number -@@ -700,6 +701,28 @@ dit(bf(--include-from=FILE)) This specif +@@ -711,6 +712,28 @@ dit(bf(--include-from=FILE)) This specif from a file. If em(FILE) is "-" the list will be read from standard input. @@ -714,7 +750,7 @@ contained a slash. dit(bf(--files-from=FILE)) Using this option allows you to specify the exact list of files to transfer (as read from the specified FILE or "-" for standard input). It also tweaks the default behavior of rsync to make -@@ -1052,6 +1075,11 @@ itemize( +@@ -1086,6 +1109,11 @@ itemize( then it is always considered an exclude pattern, even if specified as part of an include option. The prefix is discarded before matching. @@ -726,7 +762,7 @@ contained a slash. it() if the pattern is a single exclamation mark ! then the current include/exclude list is reset, removing all previously defined patterns. ) -@@ -1104,6 +1132,67 @@ itemize( +@@ -1138,6 +1166,67 @@ itemize( it would be excluded by the "*") )