From: Pádraig Brady Date: Mon, 20 Jan 2025 15:21:58 +0000 (+0000) Subject: tests: remove use of unprotected 'set' X-Git-Tag: v9.7~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dcc896e6c3d7fdcb75f493e216f94a2af558740b;p=thirdparty%2Fcoreutils.git tests: remove use of unprotected 'set' * 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. --- diff --git a/cfg.mk b/cfg.mk index bafee5990a..a085194b69 100644 --- 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:' \ diff --git a/tests/cp/symlink-slash.sh b/tests/cp/symlink-slash.sh index f25eb74001..84891169ab 100755 --- a/tests/cp/symlink-slash.sh +++ b/tests/cp/symlink-slash.sh @@ -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 diff --git a/tests/ls/ls-time.sh b/tests/ls/ls-time.sh index a261ae118b..ef72644d35 100755 --- a/tests/ls/ls-time.sh +++ b/tests/ls/ls-time.sh @@ -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 diff --git a/tests/ls/symlink-slash.sh b/tests/ls/symlink-slash.sh index 5a168463b8..88dd60133d 100755 --- a/tests/ls/symlink-slash.sh +++ b/tests/ls/symlink-slash.sh @@ -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 diff --git a/tests/mkdir/perm.sh b/tests/mkdir/perm.sh index 613c5829c9..cdfe29b5f8 100755 --- a/tests/mkdir/perm.sh +++ b/tests/mkdir/perm.sh @@ -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 diff --git a/tests/mkdir/selinux.sh b/tests/mkdir/selinux.sh index 58bf7b0922..d7d63c663b 100755 --- a/tests/mkdir/selinux.sh +++ b/tests/mkdir/selinux.sh @@ -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 diff --git a/tests/mkdir/smack-no-root.sh b/tests/mkdir/smack-no-root.sh index cb98e355f0..f19d1a291a 100755 --- a/tests/mkdir/smack-no-root.sh +++ b/tests/mkdir/smack-no-root.sh @@ -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_ diff --git a/tests/mkdir/smack-root.sh b/tests/mkdir/smack-root.sh index e1fe71ae9f..373d5df34f 100755 --- a/tests/mkdir/smack-root.sh +++ b/tests/mkdir/smack-root.sh @@ -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 diff --git a/tests/mv/part-hardlink.sh b/tests/mv/part-hardlink.sh index 8229c27fad..738426604f 100755 --- a/tests/mv/part-hardlink.sh +++ b/tests/mv/part-hardlink.sh @@ -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 diff --git a/tests/nice/nice.sh b/tests/nice/nice.sh index 1b9a1bdd40..7e274ca0d2 100755 --- a/tests/nice/nice.sh +++ b/tests/nice/nice.sh @@ -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) diff --git a/tests/stty/stty-row-col.sh b/tests/stty/stty-row-col.sh index 75e98581d2..ccf8e5380d 100755 --- a/tests/stty/stty-row-col.sh +++ b/tests/stty/stty-row-col.sh @@ -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"