[Issue 21656] [REG2.091] Wrong file read during exception stringification leads to SIGBUS

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 22 20:15:40 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21656

Jacob Carlborg <doob at me.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |doob at me.com

--- Comment #6 from Jacob Carlborg <doob at me.com> ---
`thisExePath` uses `/proc/self/exe` on Linux, but it uses `readlink` to read
out the path, instead of opening the actual file.

`getprogname` is no better than `program_invocation_name`. They have more or
less the same semantics. `getprogname` returns what was stored by
`setprogname`. This is what the man pages say about `setprogname`:

The setprogname() function sets the name of the program to be the last
component of the progname argument.

The best would probably be to copy the implementation of `thisExePath`, but
change it to open the file and return a file descriptor.

A file descriptor to the executable also seems to be available in the auxiliary
vector on Linux [1]. This can be accessed with the function `getauxval` or
directly after the `envp` parameter in the C main function. I see references to
the auxiliary vector in *BSD systems as well. Might be worth checking out.

BTW, there does not seem to be a reliable way to get the path to the current
executable on OpenBSD.

[1] http://articles.manugarg.com/aboutelfauxiliaryvectors.html
[2] https://lwn.net/Articles/519085/

--


More information about the Digitalmars-d-bugs mailing list