diff options
author | Jilles Tjoelker <jilles@FreeBSD.org> | 2011-02-05 12:54:59 +0000 |
---|---|---|
committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2011-02-05 12:54:59 +0000 |
commit | 604e8224f8258ec8cf6048ce4b6e3662e112d6a8 (patch) | |
tree | 999ded504b6f93787ff21b0740db2574608bc758 /tools | |
parent | 5d40cf5d2377e9d0d3caf6f759a4379fb3466af8 (diff) | |
download | src-604e8224f8258ec8cf6048ce4b6e3662e112d6a8.tar.gz src-604e8224f8258ec8cf6048ce4b6e3662e112d6a8.zip |
sh: Do not try to execute binary files as scripts.
If execve() returns an [ENOEXEC] error, check if the file is binary before
trying to execute it using sh. A file is considered binary if at least one
of the first 256 bytes is '\0'.
In particular, trying to execute ELF binaries for the wrong architecture now
fails with an "Exec format error" message instead of syntax errors and
potentially strange results.
Notes
Notes:
svn path=/head/; revision=218320
Diffstat (limited to 'tools')
-rw-r--r-- | tools/regression/bin/sh/errors/bad-binary1.126 | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/regression/bin/sh/errors/bad-binary1.126 b/tools/regression/bin/sh/errors/bad-binary1.126 new file mode 100644 index 000000000000..d92e9ded5689 --- /dev/null +++ b/tools/regression/bin/sh/errors/bad-binary1.126 @@ -0,0 +1,12 @@ +# $FreeBSD$ +# Checking for binary "scripts" without magic number is permitted but not +# required by POSIX. However, it is preferable to getting errors like +# Syntax error: word unexpected (expecting ")") +# from trying to execute ELF binaries for the wrong architecture. + +T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit +trap 'rm -rf "${T}"' 0 +printf '\0echo bad\n' >"$T/testshellproc" +chmod 755 "$T/testshellproc" +PATH=$T:$PATH +testshellproc 2>/dev/null |