From: Jim Meyering Date: Sun, 16 Sep 2007 09:07:59 +0000 (+0200) Subject: tests/CuTmpdir.pm: Use File::Find + chmod syscall, not chmod -R. X-Git-Tag: v6.9.89~108 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d423f4a14b19a9771510cc753a0781dbbe1bf0ff;p=thirdparty%2Fcoreutils.git tests/CuTmpdir.pm: Use File::Find + chmod syscall, not chmod -R. Signed-off-by: Jim Meyering --- diff --git a/ChangeLog b/ChangeLog index d021f5dc82..5ecf7592de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2007-09-16 Jim Meyering + * tests/CuTmpdir.pm: Use File::Find + chmod syscall, not chmod -R. + Revamp most test scripts. * tests/rm/v-slash: Avoid test failure with non-C locale. diff --git a/tests/CuTmpdir.pm b/tests/CuTmpdir.pm index e92feff5d3..f8d43d5ff7 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; }