mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 02:49:02 -04:00
Reject invalid filter specifications
This commit is contained in:
parent
c35580e630
commit
d493277ea1
4 changed files with 30 additions and 6 deletions
3
HISTORY
3
HISTORY
|
|
@ -1,9 +1,10 @@
|
|||
SnapRAID HISTORY
|
||||
================
|
||||
|
||||
8.2 2015/06
|
||||
8.2 2015/08
|
||||
===========
|
||||
* Update 'best' RAID functions for recent Atom CPUs.
|
||||
* Validate filters specificatinos rejecting relative paths.
|
||||
|
||||
8.1 2015/05
|
||||
===========
|
||||
|
|
|
|||
|
|
@ -270,6 +270,9 @@ endif
|
|||
echo --- Filter
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) -d disk1 check > output.log
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) -f \\*a -f a/ -f /b/a\\* check > output.log
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) --test-expect-failure -f . check > output.log
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) --test-expect-failure -f ./ check > output.log
|
||||
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) --test-expect-failure -f a/a check > output.log
|
||||
echo --- Delete some files and sync
|
||||
rm bench/disk4/a/9*
|
||||
rm bench/disk5/a/9*
|
||||
|
|
|
|||
3
TODO
3
TODO
|
|
@ -5,9 +5,6 @@ This is the list of TODO items for SnapRAID.
|
|||
|
||||
- Next
|
||||
|
||||
* Check if filters contains "." or "..". Return an error in this case.
|
||||
Command line with -f. And also exclude/include rules.
|
||||
|
||||
* Allow to scrub/check/verify the just synched data.
|
||||
Like an option to scrub only recent data.
|
||||
Or more simply, we can add a new option at sync that avoid
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ struct snapraid_filter* filter_alloc_file(int direction, const char* pattern)
|
|||
char* i;
|
||||
char* first;
|
||||
char* last;
|
||||
int token_is_valid;
|
||||
int token_is_filled;
|
||||
|
||||
filter = malloc_nofail(sizeof(struct snapraid_filter));
|
||||
pathimport(filter->pattern, sizeof(filter->pattern), pattern);
|
||||
|
|
@ -54,14 +56,37 @@ struct snapraid_filter* filter_alloc_file(int direction, const char* pattern)
|
|||
/* find first and last slash */
|
||||
first = 0;
|
||||
last = 0;
|
||||
/* reject invalid tokens, like "<empty>", ".", ".." and more dots */
|
||||
token_is_valid = 0;
|
||||
token_is_filled = 0;
|
||||
for (i = filter->pattern; *i; ++i) {
|
||||
if (*i == '/') {
|
||||
/* reject invalid tokens, but accept an empty one as first */
|
||||
if (!token_is_valid && (first != 0 || token_is_filled)) {
|
||||
free(filter);
|
||||
return 0;
|
||||
}
|
||||
token_is_valid = 0;
|
||||
token_is_filled = 0;
|
||||
|
||||
/* update slash position */
|
||||
if (!first)
|
||||
first = i;
|
||||
last = i;
|
||||
} else if (*i != '.') {
|
||||
token_is_valid = 1;
|
||||
token_is_filled = 1;
|
||||
} else {
|
||||
token_is_filled = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* reject invalid tokens, but accept an empty one as last, but not if it's the only one */
|
||||
if (!token_is_valid && (first == 0 || token_is_filled)) {
|
||||
free(filter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* it's a file filter */
|
||||
filter->is_disk = 0;
|
||||
|
||||
|
|
@ -86,10 +111,8 @@ struct snapraid_filter* filter_alloc_file(int direction, const char* pattern)
|
|||
|
||||
/* a slash must be the first char, as we don't support PATH/FILE and PATH/DIR/ */
|
||||
if (filter->pattern[0] != '/') {
|
||||
/* LCOV_EXCL_START */
|
||||
free(filter);
|
||||
return 0;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue