ENT: while (defined($_ = readdir INCOMING)) {
next ENT if m/^[.]{1,2}$/; # skip . and .. entries
# require acceptable filenames
- unless (length($_) <= MAX_FILE_NAME_LEN && /^($RE_filename_here)$/) {
+ unless (length($_) <= MAX_FILE_NAME_LEN && m/^($RE_filename_here)$/) {
m/^(.*)$/; # untaint the value
- push @trash, File::Spec->catfile($directory, $1); $badname_count++;
# This is safe for unlink (which is all we will do with @trash)
# because the filename came from a directory entry, so it must be a
# valid filename and cannot indicate directory traversal.
+ unless (m/^[.]$RE_filename_here$/) {
+ # do not unlink backup files left by cleanup and cleanup_dir
+ push @trash, File::Spec->catfile($directory, $1); $badname_count++;
+ }
next ENT
}
my $ent = $1; # if we get here, $RE_filename_here matched above
Remove all files older than one day from DIRECTORY.
As a precaution against data loss, "removed" files are actually simply
-renamed to have a leading dot. Note that, for the inbox directory,
-scan_incoming will remove those files on the next run.
+renamed to have a leading dot.
=cut
Remove FILES from the inbox, scratch, and staging directories.
As a precaution against data loss, "removed" files are actually simply
-renamed to have a leading dot. Note that, for the inbox directory,
-scan_incoming will remove those files on the next run.
+renamed to have a leading dot.
=cut
# files which are to be rejected, ignored, and removed
foreach file {
- x=x .abcfoobar -abcfoobar x;x \\~xax x*x x:x x?x ;xax _x +x
+ x=x .abcfoobar ..abcfoobar -abcfoobar x;x \\~xax x*x x:x x?x ;xax _x +x
} {
put_file [file join $tenv incoming ${file}] "bogus input $file\n"
age_file [file join $tenv incoming ${file}] "3 minutes ago"
}
+# ... except for .abcfoobar, which cleanup would produce when removing a
+# file named "abcfoobar", which is an acceptable name
start_test_services $tenv
run_upload_batch_test
analyze_file_tree $tenv "idle processing: bogus files" {
incoming
} files {
- bogus1 bogus2 bogus3
+ bogus1 bogus2 bogus3 .abcfoobar
bo_gus bo+gus bo-gus bo~gus bo.gus
}
analyze_file_tree $tenv "idle processing: bogus files" {
!scan,x=x "ignored file: x=x"
!scan,.abcfoobar "ignored file: .abcfoobar"
+ !scan,..abcfoobar "ignored file: ..abcfoobar"
!scan,-abcfoobar "ignored file: -abcfoobar"
!scan,x;x "ignored file: x;x"
!scan,~xax "ignored file: ~xax "