From 2a3a094e0d9712e69f168a10685975f1a7ed5917 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 20 Mar 2011 08:56:06 +0100 Subject: tests: fix a bug in the cp/preserve-gid test * 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 | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'tests/cp') diff --git a/tests/cp/preserve-gid b/tests/cp/preserve-gid index ac6d221ee..552032a17 100755 --- a/tests/cp/preserve-gid +++ b/tests/cp/preserve-gid @@ -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 -- cgit v1.2.3-70-g09d2