Fixed Darwin-specific undefined behavior in get_executable_directory() #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
SIGABRT
is received by the process onDarwin
, due tofailing to fill in the buffer (
procfs
does not exist on Darwin).This causes undefined behavior in the subsequent code: null pointer dereference and attempt to write to invalid memory location (
0x0000000000000001
)NOTE: though SIGABRT is received somewhat reproducibly,
says nothing about buffer contents in case of an error, which potentially may delay the failure beyond get_executable_directory(), causing unknown side effects.
Fix
using
proc_pidpath()
was implemented for Unix (primarily Darwin and other BSD systems).Tests
the project was build using
clang 17
fromnixpkgs
, onmacOS
running onApple MacBook Air M1
. The problem could not be reproduced anymore.Click here for the details
build.sh
:shell.nix
:$ nix-shell shell.nix --run './build.sh'
The resulted build unfortunately could not find valid GPU ( which is not related to this PR).