sh: Test that executing various binary files is rejected

If executing a file fails with an [ENOEXEC] error, the shell executes the
file as a shell script, except that this execution may instead result in an
error message if the file is binary.

Per a recent Austin Group interpretation, we will need to change this to
allow a concatenation of a shell script and a binary payload. See
Austin Group bugs #1226 and #1250.

MFC after:	1 week
This commit is contained in:
Jilles Tjoelker 2019-12-30 21:32:55 +00:00
parent b0a0152ab9
commit 2a55bade0e
5 changed files with 64 additions and 0 deletions

View File

@ -55,6 +55,10 @@ ${PACKAGE}FILES+= set-x2.0
${PACKAGE}FILES+= set-x3.0
${PACKAGE}FILES+= set-x4.0
${PACKAGE}FILES+= shellproc1.0
${PACKAGE}FILES+= shellproc2.0
${PACKAGE}FILES+= shellproc3.0
${PACKAGE}FILES+= shellproc4.0
${PACKAGE}FILES+= shellproc5.0
${PACKAGE}FILES+= subshell1.0 subshell1.0.stdout
${PACKAGE}FILES+= subshell2.0
${PACKAGE}FILES+= subshell3.0

View File

@ -0,0 +1,18 @@
# $FreeBSD$
# This tests a quality of implementation issue.
# Shells are not required to reject executing binary files as shell scripts
# but executing, for example, ELF files for a different architecture as
# shell scripts may have annoying side effects.
T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit
trap 'rm -rf "${T}"' 0
printf '\0' >"$T/testshellproc"
chmod 755 "$T/testshellproc"
if [ ! -s "$T/testshellproc" ]; then
printf "printf did not write a NUL character\n" >&2
exit 2
fi
PATH=$T:$PATH
errout=`testshellproc 3>&2 2>&1 >&3 3>&-`
r=$?
[ "$r" = 126 ] && [ -n "$errout" ]

View File

@ -0,0 +1,14 @@
# $FreeBSD$
# This tests a quality of implementation issue.
# Shells are not required to reject executing binary files as shell scripts
# but executing, for example, ELF files for a different architecture as
# shell scripts may have annoying side effects.
T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit
trap 'rm -rf "${T}"' 0
printf '\177ELF\001!!\011\0\0\0\0\0\0\0\0' >"$T/testshellproc"
chmod 755 "$T/testshellproc"
PATH=$T:$PATH
errout=`testshellproc 3>&2 2>&1 >&3 3>&-`
r=$?
[ "$r" = 126 ] && [ -n "$errout" ]

View File

@ -0,0 +1,14 @@
# $FreeBSD$
# This tests a quality of implementation issue.
# Shells are not required to reject executing binary files as shell scripts
# but executing, for example, ELF files for a different architecture as
# shell scripts may have annoying side effects.
T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit
trap 'rm -rf "${T}"' 0
printf '\211PNG\015\012\032\012\0\0\0\015IHDR' >"$T/testshellproc"
chmod 755 "$T/testshellproc"
PATH=$T:$PATH
errout=`testshellproc 3>&2 2>&1 >&3 3>&-`
r=$?
[ "$r" = 126 ] && [ -n "$errout" ]

View File

@ -0,0 +1,14 @@
# $FreeBSD$
# This tests a quality of implementation issue.
# Shells are not required to reject executing binary files as shell scripts
# but executing, for example, ELF files for a different architecture as
# shell scripts may have annoying side effects.
T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit
trap 'rm -rf "${T}"' 0
printf '\177ELF\001!!\012\0\0\0\0\0\0\0\0' >"$T/testshellproc"
chmod 755 "$T/testshellproc"
PATH=$T:$PATH
errout=`testshellproc 3>&2 2>&1 >&3 3>&-`
r=$?
[ "$r" = 126 ] && [ -n "$errout" ]