diff options
author | Jim Meyering <jim@meyering.net> | 2007-09-16 11:07:59 +0200 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2007-09-16 11:29:57 +0200 |
commit | d423f4a14b19a9771510cc753a0781dbbe1bf0ff (patch) | |
tree | 0309d2915856ebfa042216c949a210a8e9de724c /tests | |
parent | 2983e54536605385b4487524e7de4ef8908c3984 (diff) | |
download | coreutils-d423f4a14b19a9771510cc753a0781dbbe1bf0ff.tar.xz |
tests/CuTmpdir.pm: Use File::Find + chmod syscall, not chmod -R.
Signed-off-by: Jim Meyering <jim@meyering.net>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CuTmpdir.pm | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/tests/CuTmpdir.pm b/tests/CuTmpdir.pm index e92feff5d..f8d43d5ff 100644 --- a/tests/CuTmpdir.pm +++ b/tests/CuTmpdir.pm @@ -20,11 +20,18 @@ use strict; use warnings; use File::Temp; +use File::Find; our $ME = $0 || "<???>"; my $dir; +sub skip_test +{ + warn "$ME: skipping test: unsafe working directory name\n"; + exit 77; +} + sub import { my $prefix = $_[1]; if ($prefix !~ /^\//) @@ -33,15 +40,35 @@ sub import { my $cwd = $@ ? '.' : Cwd::getcwd(); $prefix = "$cwd/$prefix"; } + + # Untaint for the upcoming mkdir. + $prefix =~ m!^([-+\@\w./]+)$! + or skip_test; + $prefix = $1; + $dir = File::Temp::tempdir("$prefix.tmp-XXXX", CLEANUP => 1 ); chdir $dir or warn "$ME: failed to chdir to $dir: $!\n"; } +sub wanted +{ + my $name = $_; + + # Skip symlinks and non-directories. + -l $name || !-d _ + and return; + + chmod 0700, $name; +} + END { my $saved_errno = $?; - # FIXME: use File::Find - system qw (chmod -R 700), $dir; + chdir $dir + or warn "$ME: failed to chdir to $dir: $!\n"; + # Perform the equivalent of find . -type d -print0|xargs -0 chmod -R 700. + my $options = {untaint => 1, wanted => \&wanted}; + find ($options, '.'); $? = $saved_errno; } |