diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:42:30 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:42:30 +0000 |
commit | 75808db17caf8b960b351e3408e74142f4c85aac (patch) | |
tree | 7989e9c09a4240248bf4658a22208a0a52d991c4 /t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms | |
parent | Initial commit. (diff) | |
download | lintian-upstream.tar.xz lintian-upstream.zip |
Adding upstream version 2.117.0.upstream/2.117.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 't/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms')
5 files changed, 376 insertions, 0 deletions
diff --git a/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/build-spec/debian/postinst b/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/build-spec/debian/postinst new file mode 100644 index 0000000..7004ffc --- /dev/null +++ b/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/build-spec/debian/postinst @@ -0,0 +1,87 @@ +#! /bin/sh -e + +# valid +. /usr/share/lintian/shell || exit 0 +. /usr/share/lintian/shell >/dev/null +. /usr/share/lintian/shell 2>/dev/null +. /usr/share/lintian/shell </dev/null +. "$(dirname $0)/shell" ; bar +# invalid +. /usr/share/lintian/shell foo +. "$(dirname $0)/shell" bar + +print "Hit enter to continue" +read + +H[0]='this is a string' +echo ${H[0]} +echo "Index 0's length is ${#H[0]}" +echo "All of the array is: ${H[@]}" + +# This too is a heredoc. +some-program > /etc/config-file <<'EOF' +echo "All of the array is: ${H[@]}" +EOF + +# But this isn't. +cat '<<EOF' +echo "All of the array is: ${H[@]}" +EOF + +# This is a heredoc +cat <<-EOF +echo "All of the array is ${H[@]}" +EOF + +# As is this +cat <<';' +echo "All of the array is ${H[@]}" +; + +# and this +cat <<foo +echo "All of the array is ${H[@]}" +foobar +echo $HOSTNAME +foo + +# and again +cat <<\bar +echo "All of the array is ${H[@]}" +bar + +# yet another +cat <<"x++" +echo "All of the array is ${H[@]}" +x++ + +# Recognize single quotes even if they start at the beginning of a line. +echo not a bashism \ +'/{ptex,tex}/{amstex,plain,generic,}' + +# More bashisms. +echo -e 'foo\n' +echo "${!foo}" +cat $(\< file) +select foo in a b ; do echo $foo ; done +cnt=$((cnt + 1)) +if false ; then + exec -l /bin/sh + exec -c /bin/sh + exec -a foo /bin/sh +fi +let cnt++ +if test -a /etc/default ; then + echo "$RANDOM|stuff" +fi + +# Some comment checking +# This should flag $RANDOM +test $# -gt 2 && echo $RANDOM +# But these shouldn't +test 1=1 # echo $RANDOM +(test 1=1)# echo $RANDOM +test 1=1;# echo $RANDOM +backgroundtask &#echo $RA + +#DEBHELPER# diff --git a/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/build-spec/debian/prerm b/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/build-spec/debian/prerm new file mode 100644 index 0000000..84098f7 --- /dev/null +++ b/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/build-spec/debian/prerm @@ -0,0 +1,186 @@ +#!/bin/sh + +set -e + +cat <<EOF +This is all really bad bash specific code!!! +read +source /bar/baz/bat foo +EOF + +# ok, back to checking +if [ "$2" == "purge" ]; then + rm -r /bar/baz +fi + +function foo( ) { + # but not here: local + local bar + echo "foo" &>/dev/null +} + +source $FOO + +trap "echo hi" EXIT HUP 3 + +if [[ "$2" = "purge" ]]; then + kill -HUP $$ +fi + +#this is ok though +if test -n $(echo foo | perl -pe 's/[[:space:]]//go'); then + echo 1 +fi + +# More false positives for bashism checks. None of these are errors. +echo "$line" | grep -q '{fonts/map,}/{\$progname,pdftex,dvips,}//' +echo "$line" | grep -q "${fonts},${foo}" +echo '$[1+2]' +printf "foo |& bar" +perl -e "print q( kill -HUP $? )" + +# Still catch disallowed expansions in double-quotes, though. +echo "${line:3:1}" + +# More bashisms checks + +read -x foo +read -x +read -r foo +read foo +read + +echo "a\\b" +echo 'a\nb' + +echo "${UID}" +echo "$EUID" +echo "$SHLVL" +echo "$DIRSTACK" +echo "$SECONDS" +echo "$BASH" +echo "$BASH_FOO" +echo "$SHELLOPTS" +echo "$PIPESTATUS" + +bar="$(cut '-d|' -f2 <<< "$foo")" + +VAR=1 +VAR+=a + +echos() { + echo -n -e "bar" + echo -e -n "bar" + echo -en "bar" + echo -ne "bar" + echo "bar" + echo "echo -e foo" +} + +ech.os() { + echo foo >& 2 + echo foo >&bar + echo foo >& bar +} + +echoes() { + echo "abc\nxyz" + echo 'xyz\rabc' + echo foo\cbar + + echo -e "abc\nxyz" + echo -net 'xyz\rabc' + echo -e foo\cbar +} + +foobar.() { + suspend x + suspended x + caller x + complete x + compgen x + declare -a foo +} + +.foobar() { + typeset -x bar + disown 1 + builtin foo + set -B + alias -p + unalias -a +} + +IFS="()" + +ulimit +shopt +type -v bar +time ls +dirs +diff <(tac a) <(tac b) + +pushd + +local foo=bar +local -x foo + +popd + +readonly -f + +echo bar > /dev/tcp +export x +export -x x +export -p x + +sh -x +sh -D +sh --foo +sh +O + +# Brace expansion checks +echo {a,b} +echo {abc},{bcd} + +foobar() +{ + # This is a function +} + + foo.bar() +( + # This is a function with a bad name +) + +foobar@() # foo +{ + # As is this +} + +# This is ok +read -r foo +# but these aren't +read -r +read -p "Would you like to restart the service?" foo bar +read --fish + +source "$BAR" +source '$BAR' +source ~/bar +source a + +# An example from the X maintainer scripts that used to trigger the trap +# bashism check. +trap "message;\ + message \"Received signal. Aborting $THIS_PACKAGE package $THIS_SCRIPT script.\";\ + message;\ + exit 1" HUP INT QUIT TERM + +# Also allow for extended single quotes containing double quotes. +trap 'message; + message "Received signal. Aborting $THIS_PACKAGE package $THIS_SCRIPT script."; + message; + exit 1' HUP INT QUIT TERM + +#DEBHELPER# diff --git a/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/build-spec/fill-values b/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/build-spec/fill-values new file mode 100644 index 0000000..ab87d45 --- /dev/null +++ b/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/build-spec/fill-values @@ -0,0 +1,4 @@ +Skeleton: upload-native +Testname: scripts-bashisms +Description: Check bashism detection +Extra-Build-Depends: dash (>= 0.5.10.2) diff --git a/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/eval/desc b/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/eval/desc new file mode 100644 index 0000000..ea622da --- /dev/null +++ b/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/eval/desc @@ -0,0 +1,2 @@ +Testname: scripts-bashisms +Check: shell/non-posix/bash-centric diff --git a/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/eval/hints b/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/eval/hints new file mode 100644 index 0000000..a1208c1 --- /dev/null +++ b/t/recipes/checks/shell/non-posix/bash-centric/scripts-bashisms/eval/hints @@ -0,0 +1,97 @@ +scripts-bashisms (binary): possible-bashism-in-maintainer-script '{a,b}' [prerm:143] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'unalias -a' [prerm:111] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'ulimit' [prerm:116] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'typeset' [prerm:106] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'time' [prerm:119] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'test -a' [postinst:74] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'suspend' [prerm:97] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'source ~/bar' [prerm:170] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'source a' [prerm:171] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'source /bar/baz/bat' [prerm:8] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'source '$BAR'' [prerm:169] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'source $FOO' [prerm:22] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'source "$BAR"' [prerm:168] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'shopt' [prerm:117] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'sh -D' [prerm:138] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'sh --foo' [prerm:139] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'sh +O' [prerm:140] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'set -B' [prerm:109] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'select foo' [postinst:66] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'readonly -f' [prerm:130] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'read' [prerm:7] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'read' [prerm:51] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'read' [postinst:14] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'read -x' [prerm:48] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'read -x' [prerm:47] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'read -r' [prerm:164] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'read -p' [prerm:165] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'read --fish' [prerm:166] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'pushd' [prerm:123] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'popd' [prerm:128] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'local -x' [prerm:126] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'let' [postinst:73] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'function foo(' [prerm:16] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'foobar@()' [prerm:156] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'foobar.() {' [prerm:96] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'foo.bar()' [prerm:151] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'export -x' [prerm:134] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'exec -l' [postinst:69] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'exec -c' [postinst:70] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'exec -a' [postinst:71] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'echo -ne' [prerm:92] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'echo -ne' [prerm:75] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'echo -n -e' [prerm:72] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'echo -en' [prerm:74] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'echo -e' [prerm:93] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'echo -e' [prerm:91] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'echo -e' [prerm:73] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'echo -e' [postinst:63] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'echo 'xyz\rabc'' [prerm:88] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'echo 'a\nb'' [prerm:54] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'echo "abc\nxyz"' [prerm:87] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'echo "a\\b"' [prerm:53] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'ech.os() {' [prerm:80] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'disown' [prerm:107] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'dirs' [prerm:120] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'declare' [prerm:102] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'complete' [prerm:100] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'compgen' [prerm:101] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'caller' [prerm:99] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'builtin' [prerm:108] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'alias -p' [prerm:110] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '[[' [prerm:26] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '[ "$2" ==' [prerm:12] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'VAR+=' [prerm:69] +scripts-bashisms (binary): possible-bashism-in-maintainer-script 'H[0]=' [postinst:16] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '>&bar' [prerm:82] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '>& bar' [prerm:83] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '<<<' [prerm:66] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '<(tac a)' [prerm:121] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '/dev/tcp' [prerm:132] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '.foobar() {' [prerm:105] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '. /usr/share/lintian/shell foo' [postinst:10] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '. "$(dirname $0)/shell"' [postinst:11] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '&>' [prerm:19] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '${line:3:1}' [prerm:43] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '${UID' [prerm:56] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '${H[@]}' [postinst:55] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '${H[@]}' [postinst:50] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '${H[@]}' [postinst:43] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '${H[@]}' [postinst:38] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '${H[@]}' [postinst:33] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '${H[@]}' [postinst:28] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '${H[@]}' [postinst:23] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '${H[@]}' [postinst:19] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '${H[0]}' [postinst:17] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '${#H[0]}' [postinst:18] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '${!foo}' [postinst:64] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '$SHLVL' [prerm:58] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '$SHELLOPTS' [prerm:63] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '$SECONDS' [prerm:60] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '$RANDOM' [postinst:80] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '$RANDOM' [postinst:75] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '$PIPESTATUS' [prerm:64] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '$HOSTNAME' [postinst:45] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '$EUID' [prerm:57] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '$DIRSTACK' [prerm:59] +scripts-bashisms (binary): possible-bashism-in-maintainer-script '$BASH_FOO' [prerm:62] |