mirror of
https://github.com/opnsense/src.git
synced 2026-02-14 00:04:14 -05:00
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.
12 lines
462 B
Text
12 lines
462 B
Text
# $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
|