2007-11-30 Jim Meyering <meyering@redhat.com>
+ Be extra careful to quote $abs_top_builddir-derived names.
+ * tests/misc/ls-misc (shell_quote): New function.
+ Use it to quote file names derived from $abs_top_builddir,
+ in case it contains shell meta-characters. This is not currently
+ needed, since CuTmpdir detects the fishy name and skips the test.
+ But it's important enough to add the extra protection.
+ Reported by Ralf Wildenhues.
+
Include test name in the "unsafe working directory name" diagnostic.
* tests/CuTmpdir.pm (import): If $ME is '-', use $prefix.
# Turn off localisation of executable's ouput.
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
+# If the string $S is a well-behaved file name, simply return it.
+# If it contains white space, quotes, etc., quote it, and return the new string.
+sub shell_quote($)
+{
+ my ($s) = @_;
+ if ($s =~ m![^\w+/.,-]!)
+ {
+ # Convert each single quote to '\''
+ $s =~ s/\'/\'\\\'\'/g;
+ # Then single quote the string.
+ $s = "'$s'";
+ }
+ return $s;
+}
+
# Set up files used by the setuid-etc tests; skip this entire test if
# that cannot be done.
-my $test = "$ENV{abs_top_builddir}/src/test";
+my $test = shell_quote "$ENV{abs_top_builddir}/src/test";
system (qq(touch setuid && chmod u+s setuid && $test -u setuid &&
touch setgid && chmod g+s setgid && $test -g setgid &&
mkdir sticky && chmod +t sticky && $test -k sticky &&