]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: remove use of unprotected 'set'
authorPádraig Brady <P@draigBrady.com>
Mon, 20 Jan 2025 15:21:58 +0000 (15:21 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 20 Jan 2025 15:21:58 +0000 (15:21 +0000)
* cfg.mk (sc_prohibit_bare_set): A new syntax check to
ensure we protect use of set with '--', so that args
beginning with '-' are not interpreted as options,
and if no args are present, all existing args are cleared.
* tests/cp/symlink-slash.sh: Add -- to unprotected use of set.
* tests/ls/ls-time.sh: Likewise.
* tests/ls/symlink-slash.sh: Likewise.
* tests/mkdir/perm.sh: Likewise.
* tests/mkdir/selinux.sh: Likewise.
* tests/mkdir/smack-no-root.sh: Likewise.
* tests/mkdir/smack-root.sh: Likewise.
* tests/mv/part-hardlink.sh: Likewise.
* tests/nice/nice.sh: Likewise.
* tests/stty/stty-row-col.sh: Likewise.

cfg.mk
tests/cp/symlink-slash.sh
tests/ls/ls-time.sh
tests/ls/symlink-slash.sh
tests/mkdir/perm.sh
tests/mkdir/selinux.sh
tests/mkdir/smack-no-root.sh
tests/mkdir/smack-root.sh
tests/mv/part-hardlink.sh
tests/nice/nice.sh
tests/stty/stty-row-col.sh

diff --git a/cfg.mk b/cfg.mk
index bafee5990ac92bfc90cd45cdff962a0c753f80ce..a085194b69df2c5fb859aedda9a0af29e0eab9e1 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -498,6 +498,12 @@ sc_prohibit_NULL:
        halt='use nullptr instead'                                      \
          $(_sc_search_regexp)
 
+sc_prohibit_bare_set:
+       @prohibit='^ *set [`$$]'                                        \
+       in_vc_files='\.sh$$'                                            \
+       halt='use set -- $$args instead of set $$args'                  \
+         $(_sc_search_regexp)
+
 # Don't use "indent-tabs-mode: nil" anymore.  No longer needed.
 sc_prohibit_emacs__indent_tabs_mode__setting:
        @prohibit='^( *[*#] *)?indent-tabs-mode:'                       \
index f25eb74001922c501204198f35993c0dd8323f88..84891169ab0494d7a280e02bdfcecee7dcaf049a 100755 (executable)
@@ -24,7 +24,7 @@ mkdir dir || framework_failure_
 ln -s dir symlink || framework_failure_
 
 cp -dR symlink/ s || fail=1
-set $(ls -l s)
+set -- $(ls -l s)
 
 # Prior to fileutils-4.0q, the following would have output ...'s -> dir'
 # because the trailing slash was removed unconditionally (now you have to
index a261ae118bd9729601bc3db7194b216310cff03e..ef72644d35e4971efe65599ba2d339a99a5b301e 100755 (executable)
@@ -38,7 +38,7 @@ touch -m -d "$t1" c || framework_failure_
 
 # Check default name sorting works
 for def_sort in '' '--sort=name' '-U --sort=name' '-t --sort=name'; do
-  set $(ls $def_sort a B c)
+  set -- $(ls $def_sort a B c)
   test "$*" = 'B a c' || fail=1
 done
 
@@ -53,9 +53,9 @@ touch -a -d "$u1" a || framework_failure_
 
 
 # A has ctime more recent than C.
-set $(ls -t -c a c)
+set -- $(ls -t -c a c)
 test "$*" = 'a c' || fail=1
-set $(ls -c a c)  # Not specified by POSIX
+set -- $(ls -c a c)  # Not specified by POSIX
 test "$*" = 'a c' || fail=1
 
 # Sleep so long in an attempt to avoid spurious failures
@@ -101,20 +101,20 @@ EOF
   ;;
 esac
 
-set $(ls -ut a B c)
+set -- $(ls -ut a B c)
 test "$*" = 'c B a' || fail=1
-set $(ls -u a B c)  # not specified by POSIX
+set -- $(ls -u a B c)  # not specified by POSIX
 test "$*" = 'c B a' || fail=1
 test $fail = 1 && ls -l --full-time --time=access a B c
 
-set $(ls -t a B c)
+set -- $(ls -t a B c)
 test "$*" = 'a B c' || fail=1
-set $(ls --time=mtime a B c)
+set -- $(ls --time=mtime a B c)
 test "$*" = 'a B c' || fail=1
 test $fail = 1 && ls -l --full-time a B c
 
 # Now, C should have ctime more recent than A.
-set $(ls -ct a c)
+set -- $(ls -ct a c)
 if test "$*" = 'c a'; then
   : ok
 else
index 5a168463b8177de34e65789cec0543fd02f17458..88dd60133dc070d991b7d7bf96603425c7fccebe 100755 (executable)
@@ -22,7 +22,7 @@ print_ver_ ls
 mkdir dir || framework_failure_
 ln -s dir symlink || framework_failure_
 
-set $(ls -l symlink/)
+set -- $(ls -l symlink/)
 
 # Prior to fileutils-4.0k, the following would have output '... symlink -> dir'.
 test "$*" = 'total 0' && : || fail=1
index 613c5829c9475a9963f6ad57eddb936a9ca629d8..cdfe29b5f83a0c9176f87b84780968ee95c96c67 100755 (executable)
@@ -47,7 +47,7 @@ for p in empty -p; do
 
   old_IFS=$IFS
   IFS=':'
-  set $colon_tests
+  set -- $colon_tests
   IFS=$old_IFS
 
   while :; do
index 58bf7b0922654bfd238e3adde7a86e087322bb62..d7d63c663bc608a1d4efa60a726c9773955a2eb0 100755 (executable)
@@ -33,7 +33,7 @@ for cmd_w_arg in 'mkdir dir' 'mknod b p' 'mkfifo f'; do
   # In OpenBSD's /bin/sh, mknod is a shell built-in.
   # Running via "env" ensures we run our program and not the built-in.
   env -- $cmd_w_arg --context=$c 2> out && fail=1
-  set $cmd_w_arg; cmd=$1
+  set -- $cmd_w_arg; cmd=$1
   echo "$cmd: $msg" > exp || framework_failure_
 
   # Some systems fail with ENOTSUP, EINVAL, ENOENT, or even
index cb98e355f053529050ed654b56635f8848c117ed..f19d1a291a7589865193235cff0ee62c43a3f9bc 100755 (executable)
@@ -28,7 +28,7 @@ msg="failed to set default file creation context to '$c':"
 
 for cmd in 'mkdir dir' 'mknod b p' 'mkfifo f'; do
   $cmd --context="$c" 2> out && fail=1
-  set $cmd
+  set -- $cmd
   echo "$1: $msg" > exp || framework_failure_
 
   sed -e 's/ Operation not permitted$//' out > k || framework_failure_
index e1fe71ae9fbc247860023c03e19a1efe186b5387..373d5df34f08fce7c7ecac8debb0f73977cf660b 100755 (executable)
@@ -28,7 +28,7 @@ c=arbitrary-smack-label
 
 for cmd in 'mkdir dir' 'mknod b p' 'mkfifo f'; do
   $cmd --context="$c" || { fail=1; continue; }
-  set $cmd
+  set -- $cmd
   ls -dZ $2 > out || fail=1
   test "$(cut -f1 -d' ' out)" = "$c" || { cat out; fail=1; }
 done
index 8229c27fad780a6fd8d47e7905487b855876198d..738426604f836f7f1f9e02eaeec6c2151cde43fd 100755 (executable)
@@ -35,9 +35,9 @@ mv f g "$other_partition_tmpdir" || fail=1
 mv a b "$other_partition_tmpdir" || fail=1
 
 cd "$other_partition_tmpdir"
-set $(ls -Ci f g)
+set -- $(ls -Ci f g)
 test $1 = $3 || fail=1
-set $(ls -Ci a/1 b/1)
+set -- $(ls -Ci a/1 b/1)
 test $1 = $3 || fail=1
 
 Exit $fail
index 1b9a1bdd40b8d67997f377b98a6484e02a4ecdfa..7e274ca0d2703efc5f1d9e02d85d8fc73e4dd6d7 100755 (executable)
@@ -42,7 +42,7 @@ tests='
 19 --1:-12 12
 NA LAST NA
 '
-set $tests
+set -- $tests
 
 # Require that this test be run at 'nice' level 0.
 niceness=$(nice)
index 75e98581d25840789b3f5ff18bb5823ea661ed3b..ccf8e5380d732fca31343100e4f6b7b42e6877ac 100755 (executable)
@@ -53,7 +53,7 @@ tests='
 11 rows_036 30_80
 NA LAST NA
 '
-set $tests
+set -- $tests
 
 saved_size=$(stty size) && test -n "$saved_size" \
   || skip_ "can't get window size"