cosmopolitan/ape
Jōshin 2a11a09d98
Remove realpath/getcwd from loaders (#1024)
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`.
2023-12-18 15:01:16 -05:00
..
public Improve open source compatibility 2022-09-08 03:19:35 -07:00
aarch64.lds more modeline errata (#1019) 2023-12-16 23:07:10 -05:00
ape-m1.c Remove realpath/getcwd from loaders (#1024) 2023-12-18 15:01:16 -05:00
ape.h Mint APE Loader v1.9 2023-11-05 13:11:34 -08:00
ape.internal.h Get aarch64 hello world working 2023-05-10 04:20:47 -07:00
ape.lds more modeline errata (#1019) 2023-12-16 23:07:10 -05:00
ape.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
apeinstall.sh Redesign cosmocc toolchain 2023-11-11 14:18:08 -08:00
apeuninstall.sh Redesign cosmocc toolchain 2023-11-11 14:18:08 -08:00
blink-linux-aarch64.gz Make blink support conditionally linkable into APE 2023-06-17 07:55:35 -07:00
blink-xnu-aarch64.gz Make blink support conditionally linkable into APE 2023-06-17 07:55:35 -07:00
BUILD.mk more modeline errata (#1019) 2023-12-16 23:07:10 -05:00
idata.internal.h flip et / noet in modelines 2023-12-07 22:17:11 -05:00
launch.S Loader path security (#1012) 2023-12-15 12:23:58 -05:00
loader-macho.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
loader.c Remove realpath/getcwd from loaders (#1024) 2023-12-18 15:01:16 -05:00
loader.lds more modeline errata (#1019) 2023-12-16 23:07:10 -05:00
macros.internal.h flip et / noet in modelines 2023-12-07 22:17:11 -05:00
mz.ansi Initial import 2020-06-15 07:18:57 -07:00
notice.inc Initial import 2020-06-15 07:18:57 -07:00
relocations.h Optimize memory layout 2022-09-12 04:26:52 -07:00
sections.internal.h Add <link.h> for absl 2023-12-08 20:04:10 -08:00
start.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
systemcall.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00