Allow path components with three or more dots in filter patterns

This commit is contained in:
Andrea Mazzoleni 2026-08-26 14:31:51 +02:00
parent f75827281f
commit 76e8ae2498
2 changed files with 16 additions and 1 deletions

View file

@ -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 "<empty>", ".", ".." and more dots */
/* reject invalid tokens, like "<empty>", "." 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;
}
}

View file

@ -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 },