faho · GitHub

This change modifies the fish safety check surrounding execve / spawn so
it can run shell scripts having concatenated binary content. We're using
the same safety check as FreeBSD /bin/sh [1] and the Z-shell [5].  POSIX
was recently revised to require this behavior:
    "The input file may be of any type, but the initial portion of the
     file intended to be parsed according to the shell grammar (XREF to
     XSH 2.10.2 Shell Grammar Rules) shall consist of characters and
     shall not contain the NUL character. The shell shall not enforce
     any line length limits."
    "Earlier versions of this standard required that input files to the
     shell be text files except that line lengths were unlimited.
     However, that was overly restrictive in relation to the fact that
     shells can parse a script without a trailing newline, and in
     relation to a common practice of concatenating a shell script
     ending with an 'exit' or 'exec $command' with a binary data payload
     to form a single-file self-extracting archive." [2] [3]
One example use case of such scripts, is the Cosmopolitan C Library [4]
which configuse the GNU Linker to output a polyglot shell+binary format
that runs on Linux / Mac / Windows / FreeBSD / OpenBSD / NetBSD / BIOS.
Fixes jart/cosmopolitan#88
[1] freebsd/freebsd-src@ 9a1cd36 
[2] http://austingroupbugs.net/view.php?id=1250
[3] http://austingroupbugs.net/view.php?id=1226#c4394
[4] https://justine.lol/cosmopolitan/index.html
[5] zsh-users/zsh@ 326d9c2 

@jart

@faho faho changed the title Allow more scripts without #! Allow scripts without #!

Mar 9, 2021

mqudsi

ridiculousfish added a commit that referenced this pull request

Mar 27, 2021
This adds a test for shebangless support from #7802, cleans up some of
its tricks, and includes it in the changelog.

ridiculousfish added a commit that referenced this pull request

Mar 28, 2021
This expands the heuristic introduced in #7802 to prevent implicitly
passing files ending in .fish to /bin/sh.

ridiculousfish added a commit to ridiculousfish/fish-shell that referenced this pull request

May 31, 2021
This concerns the behavior of posix_spawn for shebangless scripts. At some
point, glibc started executing them using `sh`, which is desirable for
fish's shebangless support (see fish-shell#7802). On glibcs without that behavior
the shebangless test fails. So this change disables posix_spawn on older
glibcs.
It's not easy to figure out when that happened but it definitely happens
in glibc 2.28, and does not happen in glibc 2.17. Presumably the new
behavior is present in glibc 2.24 (see BZ#23264) so that's the cutoff:
posix_spawn is no longer allowed on glibc < 2.24.
This fixes the noshebang test failures on Ubuntu Xenial and Centos 7.
See discussion at bottom of fish-shell#8021.

Closed

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators

Sep 24, 2021

Closed

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators

Nov 7, 2022

Read the original on github.com ↗