tests: fix a bug in the cp/preserve-gid test
authorJim Meyering <meyering@redhat.com>
Sun, 20 Mar 2011 07:56:06 +0000 (08:56 +0100)
committerJim Meyering <meyering@redhat.com>
Mon, 21 Mar 2011 06:37:20 +0000 (07:37 +0100)
* tests/cp/preserve-gid: Ensure that every process under test uses
the cp binary we've just built.  Before this fix, with a restrictive
umask or build-dir permissions, the UID-changing tests would end up
using whatever cp happened to be available through $PATH
Analysis by arbogast.cedric@gmail.com in http://debbugs.gnu.org/8292.

tests/cp/preserve-gid

index ac6d221..552032a 100755 (executable)
@@ -52,14 +52,6 @@ t0() {
   fi
 }
 
-t1() {
-  f=$1; shift
-  u=$1; shift
-  g=$1; shift
-  t0 "$f" "$u" "$g" setuidgid -g "$nameless_gid1,$nameless_gid2" \
-      "$nameless_uid" "$@"
-}
-
 nameless_uid=`$PERL -le '
   foreach my $i (1000..16*1024-1)
     {
@@ -105,6 +97,25 @@ t0 b1 "$nameless_uid" "$nameless_gid2" cp -p
 t0 c0 0 "$nameless_gid1" cp -p
 t0 c1 0 "$nameless_gid2" cp -p
 
+# For the remaining tests, we need a cp binary that is accessible to a user
+# with UID of $nameless_uid.  The build directory may not be accessible,
+# so create a temporary directory and copy cp into it, ensure that
+# $nameless_uid can access it and then make that directory the search path.
+tmp_path=
+cleanup_() { rm -rf "$tmp_path"; }
+tmp_path=$(mktemp -d) || fail_ "failed to create temporary directory"
+cp "$abs_path_dir_/cp" "$tmp_path"
+chown -R $nameless_uid "$tmp_path"
+
+t1() {
+  f=$1; shift
+  u=$1; shift
+  g=$1; shift
+  t0 "$f" "$u" "$g" env \
+      setuidgid -g "$nameless_gid1,$nameless_gid2" \
+      "$nameless_uid" env PATH="$tmp_path" "$@"
+}
+
 t1 a0 "$nameless_uid" "$nameless_gid1" cp
 t1 b0 "$nameless_uid" "$nameless_gid1" cp
 t1 b1 "$nameless_uid" "$nameless_gid1" cp