summaryrefslogtreecommitdiff
path: root/tests/cp
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2011-03-20 08:56:06 +0100
committerJim Meyering <meyering@redhat.com>2011-03-21 07:37:20 +0100
commit2a3a094e0d9712e69f168a10685975f1a7ed5917 (patch)
treeecee316c630ffa595a6c03ddf1c85ef348045ce9 /tests/cp
parentc20d0e17c3260915f8406c4430ee81f212b2ab18 (diff)
downloadcoreutils-2a3a094e0d9712e69f168a10685975f1a7ed5917.tar.xz
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.
Diffstat (limited to 'tests/cp')
-rwxr-xr-xtests/cp/preserve-gid27
1 files changed, 19 insertions, 8 deletions
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