Re: shebanged script not executed right - wth

From: Dag-Erling_Smørgrav <des_at_FreeBSD.org>
Date: Sat, 09 Aug 2025 13:05:16 UTC
Dag-Erling Smørgrav <des@FreeBSD.org> writes:
> [...] there is nothing in the code to prevent [double indirection]
> from working, and it does seem to work on 13, 14, and 15 [...]

Right, so in my testing, I was able to do double indirection (the
interpreter can be interpreted) but not triple indirection (the
interpreter's interpreter must be a binary).

I think the reason double indirection works is that the first level of
indirection is handled by the shell (this will obviously vary from one
shell to another), so the kernel only sees the second.  Thus double
indirection becomes single indirection, which is permitted, and triple
indirection becomes double indirection, which is not.

I found the place in the code that prevents double indirection, in
sys/kern/imgact_shell.c:

	/*
	 * Don't allow a shell script to be the shell for a shell
	 *	script. :-)
	 */
	if (imgp->interpreted & IMGACT_SHELL)
		return (ENOEXEC);

We could remove this with no ill effects, but I'm not sure we want to.

DES
-- 
Dag-Erling Smørgrav - des@FreeBSD.org