diff --git a/cmdline/elem.c b/cmdline/elem.c index c975575c..ebabfc1a 100644 --- a/cmdline/elem.c +++ b/cmdline/elem.c @@ -39,6 +39,7 @@ struct snapraid_filter* filter_alloc_file(int direction, const char* root, const char* last; int token_is_valid; int token_is_filled; + int token_dot_count; filter = malloc_nofail(sizeof(struct snapraid_filter)); pathimport(filter->pattern, sizeof(filter->pattern), pattern); @@ -55,9 +56,10 @@ struct snapraid_filter* filter_alloc_file(int direction, const char* root, const first = 0; last = 0; - /* reject invalid tokens, like "", ".", ".." and more dots */ + /* reject invalid tokens, like "", "." and ".." */ token_is_valid = 0; token_is_filled = 0; + token_dot_count = 0; for (i = filter->pattern; *i; ++i) { if (*i == '/') { /* reject invalid tokens, but accept an empty one as first */ @@ -67,6 +69,7 @@ struct snapraid_filter* filter_alloc_file(int direction, const char* root, const } token_is_valid = 0; token_is_filled = 0; + token_dot_count = 0; /* update slash position */ if (!first) @@ -77,6 +80,9 @@ struct snapraid_filter* filter_alloc_file(int direction, const char* root, const token_is_filled = 1; } else { token_is_filled = 1; + ++token_dot_count; + if (token_dot_count >= 3) + token_is_valid = 1; } } diff --git a/cmdline/selftest.c b/cmdline/selftest.c index e402d154..01b49497 100644 --- a/cmdline/selftest.c +++ b/cmdline/selftest.c @@ -903,8 +903,17 @@ struct { /* invalid standalone root and standalone double-star patterns */ { "/", 0 }, { "/**/", 0 }, + { ".", 0 }, + { "..", 0 }, + { "/./", 0 }, + { "/../", 0 }, /* valid single and multi-level patterns */ + { "...", 1 }, + { ".../", 1 }, + { "/.../", 1 }, + { "....", 1 }, + { "/foo/.../bar", 1 }, { "/foo/", 1 }, { "/foo/**/", 1 }, { "/**/foo/", 1 },