Why Nostr? What is Njump?
2023-06-27 06:33:39

chris on Nostr: TIL that on FreeBSD, the interpreter in the shebang line of a script must be a binary ...

TIL that on FreeBSD, the interpreter in the shebang line of a script must be a binary executable (presumably ELF), not a script or similar. On Linux, using a script as an interpreter is totally cool. The fix is easy: just use #!/usr/bin/env in the shebang line, which is probably a good idea anyway. If your shebang line does happen to point to a script, execution doesn’t fail. Oh no. Instead, the system shell is invoked with whatever you were trying to pass to some other interpreter. This is absolutely terrible. Instead of getting a sane error message like “Sorry Dave, I can’t do that, and here’s why”, you’ll get some bizarre syntax error from the shell … if you’re lucky! If you are particularly unlucky, then who the fuck knows what will happen. Your guess is as good as mine.

Somewhat relatedly, the following has made its rounds on HN and Lobsters more than once: Actually Portable Executables. For people who haven’t seen it, this is basically a technique to create a “polyglot” x86 binary that runs on Unix, DOS/Windows, Mac, bare metal, and so forth. On Unix, this works by exploiting an ancient misfeature that has evidently been codified in bloody POSIX. Here’s a longish quote from the post:

One day, while studying old code, I found out that it’s possible to encode Windows Portable Executable files as a UNIX Sixth Edition shell script, due to the fact that the Thompson Shell didn’t use a shebang line. Once I realized it’s possible to create a synthesis of the binary formats being used by Unix, Windows, and MacOS, I couldn’t resist the temptation of making it a reality, since it means that high-performance native code can be almost as pain-free as web apps. Here’s how it works:

There are already plenty of ways to use the wrong interpreter on the wrong code. This one would be easy to prevent. But nope, likely not gonna happen, at least on POSIX systems.
Author Public Key
npub1cfmc9zmyvltll34x63zdr0d2zxeas3zaksz0pdxfvvnwgmv59kfsdfmm05