Fix apelink shell script corruption bug

We were using a shell heredoc value '@' to terminate the dos stub, but
that's not sufficiently safe. We found out sh doesn't consider control
characters as contributing to the start of a line, and had the unlucky
chance of the linker choosing the number 2624 for e_lfanew, and that's
"@\n" in ASCII, which compromised the APE shell script.

We now use the heredoc 'justineXXXXXX' with 31 bits of entropy, that's
determistically generated by hashing apelink inputs w/ crc32 / blake2b
This commit is contained in:
Justine Tunney 2023-08-13 17:36:06 -07:00
parent 2366848db5
commit a033b65a33
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
3 changed files with 48 additions and 77 deletions

View file

@ -123,7 +123,7 @@ Cosmopolitan's third_party/gcc/ for source code and copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
EOF
exit 0
exit
fi
if [ "$1" = "--help" ]; then
@ -303,7 +303,7 @@ for x; do
elif [ x"$x" = x"-fsanitize=all" ] ||
[ x"$x" = x"-fsanitize=address" ] ||
[ x"$x" = x"-fsanitize=undefined" ]; then
fatal_error "$x use cosmo MODE=dbg rather than passing $x"
fatal_error "use cosmo MODE=dbg rather than passing $x"
elif [ x"$x" = x"-mno-red-zone" ]; then
# "Any memory below the stack beyond the red zone is considered
# volatile and may be modified by the operating system at any time."