]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests/CuTmpdir.pm: Use File::Find + chmod syscall, not chmod -R.
authorJim Meyering <jim@meyering.net>
Sun, 16 Sep 2007 09:07:59 +0000 (11:07 +0200)
committerJim Meyering <jim@meyering.net>
Sun, 16 Sep 2007 09:29:57 +0000 (11:29 +0200)
Signed-off-by: Jim Meyering <jim@meyering.net>
ChangeLog
tests/CuTmpdir.pm

index d021f5dc82df8fd9fdc69debb6073fb43d013605..5ecf7592ded12605e374d6fbff6de813c9602070 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2007-09-16  Jim Meyering  <jim@meyering.net>
 
+       * 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.
index e92feff5d3511591ff6c01ce7740aa0b0bd83337..f8d43d5ff7d565051c2d8d871bba073ae64503d1 100644 (file)
@@ -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;
 }