* tests/chgrp/from.sh: Force numeric lookup.
* tests/chmod/setgid.sh: Likewise.
* tests/chown/basic.sh: Likewise.
* tests/chown/preserve-root.sh: Likewise.
* tests/install/install-C-immutable.sh: Likewise.
* tests/install/install-C-root.sh: Likewise.
* tests/ls/nameless-uid.sh: Likewise.
* tests/misc/traversal-missing.sh: Likewise.
* tests/misc/user.sh: Likewise.
* tests/chown/deref.sh: Likewise.  Also avoid
name lookup which may fail if they contain spaces.
* tests/chown/verbose-dangling-symlink.sh: Likewise.
* tests/chgrp/verbose-dangling-symlink.sh: Likewise.
---
 tests/chgrp/from.sh                     | 2 +-
 tests/chgrp/verbose-dangling-symlink.sh | 4 ++--
 tests/chmod/setgid.sh                   | 2 +-
 tests/chown/basic.sh                    | 7 +++++++
 tests/chown/deref.sh                    | 6 +++---
 tests/chown/preserve-root.sh            | 8 ++++----
 tests/chown/verbose-dangling-symlink.sh | 5 +++--
 tests/install/install-C-immutable.sh    | 4 ++--
 tests/install/install-C-root.sh         | 8 ++++----
 tests/ls/nameless-uid.sh                | 2 +-
 tests/misc/traversal-missing.sh         | 4 ++--
 tests/misc/user.sh                      | 2 +-
 12 files changed, 31 insertions(+), 23 deletions(-)

diff --git a/tests/chgrp/from.sh b/tests/chgrp/from.sh
index 4d3636676..e66e8ded7 100755
--- a/tests/chgrp/from.sh
+++ b/tests/chgrp/from.sh
@@ -22,7 +22,7 @@ require_root_
 
 touch f || framework_failure_
 
-chgrp -R --preserve-root 1 f
+chgrp -R --preserve-root +1 f
 
 # Make sure the owner and group are 0 and 1 respectively.
 set _ $(ls -n f); shift; test ":$4" = ':1' || fail=1
diff --git a/tests/chgrp/verbose-dangling-symlink.sh 
b/tests/chgrp/verbose-dangling-symlink.sh
index edf8c8c35..a83d9bc81 100755
--- a/tests/chgrp/verbose-dangling-symlink.sh
+++ b/tests/chgrp/verbose-dangling-symlink.sh
@@ -22,7 +22,7 @@ getlimits_
 
 ln -s missing dangling-slink || framework_failure_
 
-set _ $(ls -ld dangling-slink); shift; group="$4"
+group=$(stat -c %g dangling-slink) || framework_failure_
 
 # From coreutils-5.3.0 to coreutils-9.12, this would use an
 # uninitialized struct stat.  Commonly, this would lead to the
@@ -37,7 +37,7 @@ echo "chgrp: cannot dereference 'dangling-slink': $ENOENT" 
>exp-err \
   || framework_failure_
 echo "failed to change group of 'dangling-slink' to $group" >exp-out \
   || framework_failure_
-returns_ 1 chgrp -v "$group" dangling-slink >out 2>err || fail=1
+returns_ 1 chgrp -v "+$group" dangling-slink >out 2>err || fail=1
 compare exp-out out || fail=1
 compare exp-err err || fail=1
 
diff --git a/tests/chmod/setgid.sh b/tests/chmod/setgid.sh
index d4bcd086d..5e69e3edc 100755
--- a/tests/chmod/setgid.sh
+++ b/tests/chmod/setgid.sh
@@ -34,7 +34,7 @@ chmod g+s d 2> /dev/null && env -- test -g d ||
 
     for id_g in $(id -g) $(id -G) ''; do
       test -n "$id_g" || break
-      chgrp "$id_g" d && chmod g+s d && env -- test -g d && break
+      chgrp "+$id_g" d && chmod g+s d && env -- test -g d && break
     done
     test -n "$id_g"
   } ||
diff --git a/tests/chown/basic.sh b/tests/chown/basic.sh
index 16b6c94b0..b5f0c6858 100755
--- a/tests/chown/basic.sh
+++ b/tests/chown/basic.sh
@@ -20,6 +20,13 @@
 print_ver_ chown
 require_root_
 
+# Numeric user names must not resolve to different user IDs.
+for user in 0 2 42 43; do
+  uid=$(id -u "$user" 2>/dev/null) || continue
+  test "$uid" = "$user" ||
+    skip_ "user name '$user' resolves to UID $uid"
+done
+
 touch f || framework_failure_
 
 chown -R --preserve-root 0:1 f
diff --git a/tests/chown/deref.sh b/tests/chown/deref.sh
index 9fbb93f86..ae930f793 100755
--- a/tests/chown/deref.sh
+++ b/tests/chown/deref.sh
@@ -23,10 +23,10 @@ print_ver_ chown
 ln -s no-such dangle || framework_failure_
 
 
-set _ $(ls -ldo dangle); shift; user=$3
+user=$(stat -c %u dangle) || framework_failure_
 
 # With 5.2.1 and earlier, this command would mistakenly succeed.
-chown --dereference $user dangle 2> out1 && fail=1
+chown --dereference "+$user" dangle 2> out1 && fail=1
 sed 's/: [^:]*$//' out1 > out
 
 cat <<\EOF > exp || framework_failure_
@@ -40,7 +40,7 @@ compare exp out || fail=1
 # rather than descend into it forever.
 mkdir -p cyc/b/c || framework_failure_
 ln -s "$(pwd)/cyc" cyc/b/c/d || framework_failure_
-chown -vRL $user cyc > out2 2>&1 || fail=1
+chown -vRL "+$user" cyc > out2 2>&1 || fail=1
 # The symlinked directory is visited exactly once...
 grep -F "'cyc/b/c/d'" out2 > /dev/null || { cat out2; fail=1; }
 # ...and recursion does not re-enter it through the cycle.
diff --git a/tests/chown/preserve-root.sh b/tests/chown/preserve-root.sh
index 11355dada..fea84adc1 100755
--- a/tests/chown/preserve-root.sh
+++ b/tests/chown/preserve-root.sh
@@ -43,13 +43,13 @@ chmod -R --preserve-root u+r / >> out 2>&1 && fail=1
 # since the symlink in question is not a command line argument.
 # Contrary to the above commands, these two should succeed.
 echo '==== test -RHh' >> out || framework_failure_
-chown -RHh --preserve-root $(id -u) d >> out 2>&1 || fail=1
-test -z "$id_g" || chgrp -RHh --preserve-root "$id_g" d >> out 2>&1 || fail=1
+chown -RHh --preserve-root "+$(id -u)" d >> out 2>&1 || fail=1
+test -z "$id_g" || chgrp -RHh --preserve-root "+$id_g" d >> out 2>&1 || fail=1
 
 # These must fail.
 echo '==== test -RLh' >> out || framework_failure_
-chown -RLh --preserve-root $(id -u) d >> out 2>&1 && fail=1
-test -n "$id_g" && chgrp -RLh --preserve-root "$id_g" d >> out 2>&1 && fail=1
+chown -RLh --preserve-root "+$(id -u)" d >> out 2>&1 && fail=1
+test -n "$id_g" && chgrp -RLh --preserve-root "+$id_g" d >> out 2>&1 && fail=1
 
 (
  cat <<\EOF &&
diff --git a/tests/chown/verbose-dangling-symlink.sh 
b/tests/chown/verbose-dangling-symlink.sh
index e64370789..ed417f138 100755
--- a/tests/chown/verbose-dangling-symlink.sh
+++ b/tests/chown/verbose-dangling-symlink.sh
@@ -22,7 +22,8 @@ getlimits_
 
 ln -s missing dangling-slink || framework_failure_
 
-set _ $(ls -ld dangling-slink); shift; user="$3"; group="$4"
+user=$(stat -c %u dangling-slink) &&
+group=$(stat -c %g dangling-slink) || framework_failure_
 
 # From coreutils-5.3.0 to coreutils-9.12, this would use an
 # uninitialized struct stat.  Commonly, this would lead to the
@@ -38,7 +39,7 @@ echo "chown: cannot dereference 'dangling-slink': $ENOENT" 
>exp-err \
   || framework_failure_
 echo "failed to change ownership of 'dangling-slink' to $user:$group" \
   >exp-out || framework_failure_
-returns_ 1 chown -v "$user":"$group" dangling-slink >out 2>err || fail=1
+returns_ 1 chown -v "+$user:+$group" dangling-slink >out 2>err || fail=1
 compare exp-out out || fail=1
 compare exp-err err || fail=1
 
diff --git a/tests/install/install-C-immutable.sh 
b/tests/install/install-C-immutable.sh
index 0bdb97997..c21c76916 100755
--- a/tests/install/install-C-immutable.sh
+++ b/tests/install/install-C-immutable.sh
@@ -38,8 +38,8 @@ if test $chattr_i_works = 0; then
   skip_ "chattr +i doesn't work on this file system"
 fi
 
-u1=1
-g1=1
+u1=+1
+g1=+1
 
 echo test > a || framework_failure_
 
diff --git a/tests/install/install-C-root.sh b/tests/install/install-C-root.sh
index cba3c167d..23905d8bb 100755
--- a/tests/install/install-C-root.sh
+++ b/tests/install/install-C-root.sh
@@ -22,10 +22,10 @@ require_root_
 skip_if_setgid_
 skip_if_nondefault_group_
 
-u1=1
-u2=2
-g1=1
-g2=2
+u1=+1
+u2=+2
+g1=+1
+g2=+2
 
 
 echo test > a || framework_failure_
diff --git a/tests/ls/nameless-uid.sh b/tests/ls/nameless-uid.sh
index 567143753..62b45920d 100755
--- a/tests/ls/nameless-uid.sh
+++ b/tests/ls/nameless-uid.sh
@@ -31,7 +31,7 @@ if test x$nameless_uid = x; then
 fi
 
 touch f || framework_failure_
-chown $nameless_uid f || framework_failure_
+chown +$nameless_uid f || framework_failure_
 
 
 set -- $(ls -o f) || fail=1
diff --git a/tests/misc/traversal-missing.sh b/tests/misc/traversal-missing.sh
index 764d9ca10..633ea0be8 100755
--- a/tests/misc/traversal-missing.sh
+++ b/tests/misc/traversal-missing.sh
@@ -60,8 +60,8 @@ for errnum in ENOENT EIO; do
   run_injected_ foo "$stats" ls -l .
   run_injected_ foo "$stats" du -a .
   run_injected_ foo "$chmods" chmod -R 0700 .
-  run_injected_ foo "$chowns" chown -R "$uid" .
-  run_injected_ foo "$chowns" chgrp -R "$gid" .
+  run_injected_ foo "$chowns" chown -R "+$uid" .
+  run_injected_ foo "$chowns" chgrp -R "+$gid" .
 done
 
 Exit $fail
diff --git a/tests/misc/user.sh b/tests/misc/user.sh
index 931287e41..f9ca2f72b 100755
--- a/tests/misc/user.sh
+++ b/tests/misc/user.sh
@@ -23,7 +23,7 @@ unshare -U unshare --version || skip_ 'unshare -U is 
unavailable'
 overflow_uid=$(cat /proc/sys/kernel/overflowuid) ||
  skip_ 'overflow uid is unavailable'
 
-test "$(unshare -U whoami)" = "$(id -un $overflow_uid)" || fail=1
+test "$(unshare -U whoami)" = "$(id -un "+$overflow_uid")" || fail=1
 
 # The "</dev/null" disables a fallback lookup via utmp/utmpx,
 # that existed in glibc < 2.28 and exists again in glibc >= 2.38.
-- 
2.56.0


Reply via email to