From d423f4a14b19a9771510cc753a0781dbbe1bf0ff Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 16 Sep 2007 11:07:59 +0200 Subject: tests/CuTmpdir.pm: Use File::Find + chmod syscall, not chmod -R. Signed-off-by: Jim Meyering --- tests/CuTmpdir.pm | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'tests') 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; } -- cgit v1.2.3-70-g09d2