Commit 7e43da81 authored by Wayne Davison's avatar Wayne Davison

If we're sanitizing paths with --relative enabled, we need to

preserve the first /./ dir so that we can use its position to
trim the implied directories.
parent 40aaa571
...@@ -31,6 +31,7 @@ extern int verbose; ...@@ -31,6 +31,7 @@ extern int verbose;
extern int dry_run; extern int dry_run;
extern int module_id; extern int module_id;
extern int modify_window; extern int modify_window;
extern int relative_paths;
extern char *partial_dir; extern char *partial_dir;
extern struct filter_list_struct server_filter_list; extern struct filter_list_struct server_filter_list;
...@@ -755,7 +756,7 @@ unsigned int clean_fname(char *name, BOOL collapse_dot_dot) ...@@ -755,7 +756,7 @@ unsigned int clean_fname(char *name, BOOL collapse_dot_dot)
char *sanitize_path(char *dest, const char *p, const char *rootdir, int depth) char *sanitize_path(char *dest, const char *p, const char *rootdir, int depth)
{ {
char *start, *sanp; char *start, *sanp;
int rlen = 0; int rlen = 0, leave_one_dotdir = relative_paths;
if (dest != p) { if (dest != p) {
int plen = strlen(p); int plen = strlen(p);
...@@ -790,10 +791,14 @@ char *sanitize_path(char *dest, const char *p, const char *rootdir, int depth) ...@@ -790,10 +791,14 @@ char *sanitize_path(char *dest, const char *p, const char *rootdir, int depth)
* always be left pointing after a slash * always be left pointing after a slash
*/ */
if (*p == '.' && (p[1] == '/' || p[1] == '\0')) { if (*p == '.' && (p[1] == '/' || p[1] == '\0')) {
if (leave_one_dotdir && p[1] && sanp != dest)
leave_one_dotdir = 0;
else {
/* skip "." component */ /* skip "." component */
p++; p++;
continue; continue;
} }
}
if (*p == '.' && p[1] == '.' && (p[2] == '/' || p[2] == '\0')) { if (*p == '.' && p[1] == '.' && (p[2] == '/' || p[2] == '\0')) {
/* ".." component followed by slash or end */ /* ".." component followed by slash or end */
if (depth <= 0 || sanp != start) { if (depth <= 0 || sanp != start) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment