btrbk: check/sanitize leading/trailing whitespace on files

unsafe-filenames
Axel Burri 2021-08-15 18:24:41 +02:00
parent 77a39282de
commit 94a415e420
1 changed files with 7 additions and 0 deletions

7
btrbk
View File

@ -3915,10 +3915,17 @@ sub check_file($$;@)
return undef;
}
if($sanitize) {
$file =~ s/^\s+//;
$file =~ s/\s+$//;
$file =~ s/\/(\.?\/)+/\//g; # sanitize "//", "/./" -> "/"
$file =~ s/\/\.$/\//; # sanitize trailing "/." -> "/"
$file =~ s/\/$// unless($file eq '/'); # remove trailing slash
}
elsif(($file =~ /^\s/) || ($file =~ /\s$/)) {
ERROR "Illegal leading/trailing whitespace ${error_statement}: \"$file\"" if(defined($error_statement));
return undef;
}
return $file;
}