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/regular-shipped | |
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/regular-shipped')
6 files changed, 377 insertions, 0 deletions
diff --git a/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/build-spec/debian/install b/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/build-spec/debian/install new file mode 100644 index 0000000..aaad16b --- /dev/null +++ b/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/build-spec/debian/install @@ -0,0 +1 @@ +scripts/* usr/bin diff --git a/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/build-spec/fill-values b/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/build-spec/fill-values new file mode 100644 index 0000000..8efbbf3 --- /dev/null +++ b/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/build-spec/fill-values @@ -0,0 +1,4 @@ +Testname: regular-shipped +Skeleton: upload-non-native +Description: Check bashism detection +Extra-Build-Depends: dash (>= 0.5.10.2) diff --git a/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/build-spec/orig/scripts/one b/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/build-spec/orig/scripts/one new file mode 100644 index 0000000..7004ffc --- /dev/null +++ b/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/build-spec/orig/scripts/one @@ -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/regular-shipped/build-spec/orig/scripts/two b/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/build-spec/orig/scripts/two new file mode 100644 index 0000000..84098f7 --- /dev/null +++ b/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/build-spec/orig/scripts/two @@ -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/regular-shipped/eval/desc b/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/eval/desc new file mode 100644 index 0000000..aa7af08 --- /dev/null +++ b/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/eval/desc @@ -0,0 +1,2 @@ +Testname: regular-shipped +Check: shell/non-posix/bash-centric diff --git a/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/eval/hints b/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/eval/hints new file mode 100644 index 0000000..94e10dc --- /dev/null +++ b/t/recipes/checks/shell/non-posix/bash-centric/regular-shipped/eval/hints @@ -0,0 +1,97 @@ +regular-shipped (binary): bash-term-in-posix-shell '{a,b}' [usr/bin/two:143] +regular-shipped (binary): bash-term-in-posix-shell 'unalias -a' [usr/bin/two:111] +regular-shipped (binary): bash-term-in-posix-shell 'ulimit' [usr/bin/two:116] +regular-shipped (binary): bash-term-in-posix-shell 'typeset' [usr/bin/two:106] +regular-shipped (binary): bash-term-in-posix-shell 'time' [usr/bin/two:119] +regular-shipped (binary): bash-term-in-posix-shell 'test -a' [usr/bin/one:74] +regular-shipped (binary): bash-term-in-posix-shell 'suspend' [usr/bin/two:97] +regular-shipped (binary): bash-term-in-posix-shell 'source ~/bar' [usr/bin/two:170] +regular-shipped (binary): bash-term-in-posix-shell 'source a' [usr/bin/two:171] +regular-shipped (binary): bash-term-in-posix-shell 'source /bar/baz/bat' [usr/bin/two:8] +regular-shipped (binary): bash-term-in-posix-shell 'source '$BAR'' [usr/bin/two:169] +regular-shipped (binary): bash-term-in-posix-shell 'source $FOO' [usr/bin/two:22] +regular-shipped (binary): bash-term-in-posix-shell 'source "$BAR"' [usr/bin/two:168] +regular-shipped (binary): bash-term-in-posix-shell 'shopt' [usr/bin/two:117] +regular-shipped (binary): bash-term-in-posix-shell 'sh -D' [usr/bin/two:138] +regular-shipped (binary): bash-term-in-posix-shell 'sh --foo' [usr/bin/two:139] +regular-shipped (binary): bash-term-in-posix-shell 'sh +O' [usr/bin/two:140] +regular-shipped (binary): bash-term-in-posix-shell 'set -B' [usr/bin/two:109] +regular-shipped (binary): bash-term-in-posix-shell 'select foo' [usr/bin/one:66] +regular-shipped (binary): bash-term-in-posix-shell 'readonly -f' [usr/bin/two:130] +regular-shipped (binary): bash-term-in-posix-shell 'read' [usr/bin/two:7] +regular-shipped (binary): bash-term-in-posix-shell 'read' [usr/bin/two:51] +regular-shipped (binary): bash-term-in-posix-shell 'read' [usr/bin/one:14] +regular-shipped (binary): bash-term-in-posix-shell 'read -x' [usr/bin/two:48] +regular-shipped (binary): bash-term-in-posix-shell 'read -x' [usr/bin/two:47] +regular-shipped (binary): bash-term-in-posix-shell 'read -r' [usr/bin/two:164] +regular-shipped (binary): bash-term-in-posix-shell 'read -p' [usr/bin/two:165] +regular-shipped (binary): bash-term-in-posix-shell 'read --fish' [usr/bin/two:166] +regular-shipped (binary): bash-term-in-posix-shell 'pushd' [usr/bin/two:123] +regular-shipped (binary): bash-term-in-posix-shell 'popd' [usr/bin/two:128] +regular-shipped (binary): bash-term-in-posix-shell 'local -x' [usr/bin/two:126] +regular-shipped (binary): bash-term-in-posix-shell 'let' [usr/bin/one:73] +regular-shipped (binary): bash-term-in-posix-shell 'function foo(' [usr/bin/two:16] +regular-shipped (binary): bash-term-in-posix-shell 'foobar@()' [usr/bin/two:156] +regular-shipped (binary): bash-term-in-posix-shell 'foobar.() {' [usr/bin/two:96] +regular-shipped (binary): bash-term-in-posix-shell 'foo.bar()' [usr/bin/two:151] +regular-shipped (binary): bash-term-in-posix-shell 'export -x' [usr/bin/two:134] +regular-shipped (binary): bash-term-in-posix-shell 'exec -l' [usr/bin/one:69] +regular-shipped (binary): bash-term-in-posix-shell 'exec -c' [usr/bin/one:70] +regular-shipped (binary): bash-term-in-posix-shell 'exec -a' [usr/bin/one:71] +regular-shipped (binary): bash-term-in-posix-shell 'echo -ne' [usr/bin/two:92] +regular-shipped (binary): bash-term-in-posix-shell 'echo -ne' [usr/bin/two:75] +regular-shipped (binary): bash-term-in-posix-shell 'echo -n -e' [usr/bin/two:72] +regular-shipped (binary): bash-term-in-posix-shell 'echo -en' [usr/bin/two:74] +regular-shipped (binary): bash-term-in-posix-shell 'echo -e' [usr/bin/two:93] +regular-shipped (binary): bash-term-in-posix-shell 'echo -e' [usr/bin/two:91] +regular-shipped (binary): bash-term-in-posix-shell 'echo -e' [usr/bin/two:73] +regular-shipped (binary): bash-term-in-posix-shell 'echo -e' [usr/bin/one:63] +regular-shipped (binary): bash-term-in-posix-shell 'echo 'xyz\rabc'' [usr/bin/two:88] +regular-shipped (binary): bash-term-in-posix-shell 'echo 'a\nb'' [usr/bin/two:54] +regular-shipped (binary): bash-term-in-posix-shell 'echo "abc\nxyz"' [usr/bin/two:87] +regular-shipped (binary): bash-term-in-posix-shell 'echo "a\\b"' [usr/bin/two:53] +regular-shipped (binary): bash-term-in-posix-shell 'ech.os() {' [usr/bin/two:80] +regular-shipped (binary): bash-term-in-posix-shell 'disown' [usr/bin/two:107] +regular-shipped (binary): bash-term-in-posix-shell 'dirs' [usr/bin/two:120] +regular-shipped (binary): bash-term-in-posix-shell 'declare' [usr/bin/two:102] +regular-shipped (binary): bash-term-in-posix-shell 'complete' [usr/bin/two:100] +regular-shipped (binary): bash-term-in-posix-shell 'compgen' [usr/bin/two:101] +regular-shipped (binary): bash-term-in-posix-shell 'caller' [usr/bin/two:99] +regular-shipped (binary): bash-term-in-posix-shell 'builtin' [usr/bin/two:108] +regular-shipped (binary): bash-term-in-posix-shell 'alias -p' [usr/bin/two:110] +regular-shipped (binary): bash-term-in-posix-shell '[[' [usr/bin/two:26] +regular-shipped (binary): bash-term-in-posix-shell '[ "$2" ==' [usr/bin/two:12] +regular-shipped (binary): bash-term-in-posix-shell 'VAR+=' [usr/bin/two:69] +regular-shipped (binary): bash-term-in-posix-shell 'H[0]=' [usr/bin/one:16] +regular-shipped (binary): bash-term-in-posix-shell '>&bar' [usr/bin/two:82] +regular-shipped (binary): bash-term-in-posix-shell '>& bar' [usr/bin/two:83] +regular-shipped (binary): bash-term-in-posix-shell '<<<' [usr/bin/two:66] +regular-shipped (binary): bash-term-in-posix-shell '<(tac a)' [usr/bin/two:121] +regular-shipped (binary): bash-term-in-posix-shell '/dev/tcp' [usr/bin/two:132] +regular-shipped (binary): bash-term-in-posix-shell '.foobar() {' [usr/bin/two:105] +regular-shipped (binary): bash-term-in-posix-shell '. /usr/share/lintian/shell foo' [usr/bin/one:10] +regular-shipped (binary): bash-term-in-posix-shell '. "$(dirname $0)/shell"' [usr/bin/one:11] +regular-shipped (binary): bash-term-in-posix-shell '&>' [usr/bin/two:19] +regular-shipped (binary): bash-term-in-posix-shell '${line:3:1}' [usr/bin/two:43] +regular-shipped (binary): bash-term-in-posix-shell '${UID' [usr/bin/two:56] +regular-shipped (binary): bash-term-in-posix-shell '${H[@]}' [usr/bin/one:55] +regular-shipped (binary): bash-term-in-posix-shell '${H[@]}' [usr/bin/one:50] +regular-shipped (binary): bash-term-in-posix-shell '${H[@]}' [usr/bin/one:43] +regular-shipped (binary): bash-term-in-posix-shell '${H[@]}' [usr/bin/one:38] +regular-shipped (binary): bash-term-in-posix-shell '${H[@]}' [usr/bin/one:33] +regular-shipped (binary): bash-term-in-posix-shell '${H[@]}' [usr/bin/one:28] +regular-shipped (binary): bash-term-in-posix-shell '${H[@]}' [usr/bin/one:23] +regular-shipped (binary): bash-term-in-posix-shell '${H[@]}' [usr/bin/one:19] +regular-shipped (binary): bash-term-in-posix-shell '${H[0]}' [usr/bin/one:17] +regular-shipped (binary): bash-term-in-posix-shell '${#H[0]}' [usr/bin/one:18] +regular-shipped (binary): bash-term-in-posix-shell '${!foo}' [usr/bin/one:64] +regular-shipped (binary): bash-term-in-posix-shell '$SHLVL' [usr/bin/two:58] +regular-shipped (binary): bash-term-in-posix-shell '$SHELLOPTS' [usr/bin/two:63] +regular-shipped (binary): bash-term-in-posix-shell '$SECONDS' [usr/bin/two:60] +regular-shipped (binary): bash-term-in-posix-shell '$RANDOM' [usr/bin/one:80] +regular-shipped (binary): bash-term-in-posix-shell '$RANDOM' [usr/bin/one:75] +regular-shipped (binary): bash-term-in-posix-shell '$PIPESTATUS' [usr/bin/two:64] +regular-shipped (binary): bash-term-in-posix-shell '$HOSTNAME' [usr/bin/one:45] +regular-shipped (binary): bash-term-in-posix-shell '$EUID' [usr/bin/two:57] +regular-shipped (binary): bash-term-in-posix-shell '$DIRSTACK' [usr/bin/two:59] +regular-shipped (binary): bash-term-in-posix-shell '$BASH_FOO' [usr/bin/two:62] |