Skip to content

Commit

Permalink
[FL-2997] Improve file name filtering #2047
Browse files Browse the repository at this point in the history
Co-authored-by: あく <[email protected]>
  • Loading branch information
gsurkov and skotopes authored Nov 28, 2022
1 parent 84f9af3 commit c535ce9
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions lib/toolbox/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,17 @@ bool path_contains_only_ascii(const char* path) {
name_pos++;
}

while(*name_pos != '\0') {
if((*name_pos >= '0') && (*name_pos <= '9')) {
name_pos++;
continue;
} else if((*name_pos >= 'A') && (*name_pos <= 'Z')) {
name_pos++;
continue;
} else if((*name_pos >= 'a') && (*name_pos <= 'z')) {
name_pos++;
continue;
} else if(strchr(" .!#\\$%&'()-@^_`{}~", *name_pos) != NULL) {
name_pos++;
continue;
}
for(; *name_pos; ++name_pos) {
const char c = *name_pos;

return false;
// Regular ASCII characters from 0x20 to 0x7e
const bool is_out_of_range = (c < ' ') || (c > '~');
// Cross-platform forbidden character set
const bool is_forbidden = strchr("\\<>*|\":?", c);

if(is_out_of_range || is_forbidden) {
return false;
}
}

return true;
Expand Down

0 comments on commit c535ce9

Please sign in to comment.