[PATCH] execlp, execvp, execvpe: Don't fall back to sh on ENOEXEC.
Paul Eggert
eggert@cs.ucla.edu
Tue Dec 15 20:46:46 GMT 2020
On 12/15/20 8:05 AM, Zack Weinberg wrote:
> When direct execution of a program fails with ENOEXEC, do not attempt
> to run that program as if it were a shell script.
A less-intrusive approach would be for execlp etc.'s fallback to look at the
first 1024 bytes (or whatever) of the file and fail with ENOEXEC if it finds
a NUL byte, before trying to exec /bin/sh on the file. This heuristic
surely would have addressed your problem since machine executables
invariably contain NUL bytes, and since NUL bytes cannot appear in
conforming POSIX shell scripts the heuristic would also maintain POSIX
compatibility. And as a practical matter the heuristic would continue to
support whatever random application out there is actually relying on this
longstanding POSIX-required misfeature.
More information about the Libc-alpha
mailing list