Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault on Linux when executable is started with a non-path argv[0] #714

Open
ruth-o7 opened this issue Nov 15, 2023 · 0 comments
Open

Comments

@ruth-o7
Copy link

ruth-o7 commented Nov 15, 2023

When the Pharo executable is started with an argv[0] that is not a relative or absolute path, the VM will segfault.

PoC:

wrapper.sh
#!/usr/bin/env bash
exec -a "pharo" "$(which pharo)"
$ ./wrapper.sh 
Segmentation fault (core dumped)
stack trace
              #0  0x00007f775f908c5d __strlen_avx2 (libc.so.6 + 0x15bc5d)
              #1  0x00007f775f8c9af9 __strcpy_chk (libc.so.6 + 0x11caf9)
              #2  0x00007f775fab0371 setVMPath (libPharoVMCore.so + 0x22371)
              #3  0x00007f775fab2945 vm_parameters_parse (libPharoVMCore.so + 0x24945)
              #4  0x00007f775fab17a3 vm_main (libPharoVMCore.so + 0x237a3)
              #5  0x00007f775f7d4fce __libc_start_call_main (libc.so.6 + 0x27fce)
              #6  0x00007f775f7d5089 __libc_start_main@@GLIBC_2.34 (libc.so.6 + 0x28089)
              #7  0x0000000000401075 _start (.pharo-wrapped + 0x1075)
              ELF object binary architecture: AMD x86-64

I believe this is because the realpath call in src/utils.c:getFullPath returns a NULL if the provided path does not resolve to a real file (https://man7.org/linux/man-pages/man3/realpath.3.html), which is then fed later on to setVMPath. realpath also does not look at the PATH when searching for a file.

We should log the errno at the very least, and handle this correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant