mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
This implements proposals 1 and 2a from this gist: https://gist.github.com/mrdomino/2222cab61715fd527e82e036ba4156b1 The only reason to use realpath from the loader was to try to prevent a TOCTOU between the loader and the binary. But this is only a real issue in set-id contexts, and in those cases there is already a canonical way to do it: `/dev/fd`, passed by the kernel to the loader, so all we have to do is pass that along to the binary. Aside from realpath, there is no reason to absolutize the path we supply to the binary, since it can call `getcwd` as well as we can, and on non- M1 the binary is in a much better position to make that call. Since we no longer absolutize the path, the binary does need to do this, so we make its argv-parsing code generic and apply that to the different possible places the path could come from. This means that `_` is finally usable as a relative path, as a nice side benefit. The M1 realpath code had a significant bug - it uses the wrong offset to truncate the `.ape` in the `$prog.ape` case. This PR also fixes a regression in `ape $progname` out of `$PATH` on the two BSDs (Free and Net) that did not implement `RealPath`. |
||
---|---|---|
.. | ||
public | ||
aarch64.lds | ||
ape-m1.c | ||
ape.h | ||
ape.internal.h | ||
ape.lds | ||
ape.S | ||
apeinstall.sh | ||
apeuninstall.sh | ||
blink-linux-aarch64.gz | ||
blink-xnu-aarch64.gz | ||
BUILD.mk | ||
idata.internal.h | ||
launch.S | ||
loader-macho.S | ||
loader.c | ||
loader.lds | ||
macros.internal.h | ||
mz.ansi | ||
notice.inc | ||
relocations.h | ||
sections.internal.h | ||
start.S | ||
systemcall.S |