Skip to content

os: don't resolve symlinks in find_abs_path_of_executable() #24761

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

Merged
merged 3 commits into from
Jun 23, 2025

Conversation

davidebeatrici
Copy link
Contributor

This fixes aliases and wrappers being ignored.

Resolving the symlinks can cause breakage, an example is coreutils: commands such as echo are just a symlink to a single binary. The name of the symlink tells the program which tool is requested.

Or even worse, in the case of security helpers such as firejail: a symlink is created in one of the top priority folders in PATH, so that firejail steps in and knows what to run.
Resolving the symlink would make the program run outside a jail!


Fixes #24759.

Copy link

Connected to Huly®: V_0.6-23178

@davidebeatrici davidebeatrici changed the title os: Don't resolve symlinks in find_abs_path_of_executable() os: don't resolve symlinks in find_abs_path_of_executable() Jun 20, 2025
@davidebeatrici
Copy link
Contributor Author

I will replace the uppercase letter in the commit (for consistency) when this is approved.

@spytheman
Copy link
Member

spytheman commented Jun 20, 2025

I will replace the uppercase letter in the commit (for consistency) when this is approved.

do not bother with editing it, the title of the commit in master does not depend on it (it is the title of the PR by default, but can be edited, when the PR is squash merged into master).

i.e. you can just push new commits to the same branch, no need to change the old for cosmetic stuff like typos/capitalization

@davidebeatrici
Copy link
Contributor Author

Alright, thank you.

@spytheman
Copy link
Member

You are welcome, I am happy to help.

@spytheman
Copy link
Member

Looks good so far, only a test for the issue, remains to be added.

@spytheman spytheman marked this pull request as draft June 21, 2025 03:33
@davidebeatrici davidebeatrici force-pushed the timeout-coreutils-fix branch from e92990c to db4aa8a Compare June 23, 2025 03:32
@davidebeatrici
Copy link
Contributor Author

I believe the "Ensure code is well formatted" should be in a separate, dedicated workflow. That way it's clear right away what the problem is and only one test fails.

@davidebeatrici davidebeatrici force-pushed the timeout-coreutils-fix branch from db4aa8a to d576156 Compare June 23, 2025 04:14
@davidebeatrici
Copy link
Contributor Author

On macOS:

 FAIL  [39/49] C:   329.7 ms, R:     9.791 ms vlib/os/find_abs_path_of_executable_test.v
testsuite_begin, tfolder = /tmp/v_501/tsession_1eee5cf80_01JYDG3BK5XX0VAQN6ABY567GG/filepath_tests
[/Users/runner/work/v/v/你好 my $path, @с интервали/vlib/os/find_abs_path_of_executable_test.v:34] os.abs_path(myclang_file): /tmp/v_501/tsession_1eee5cf80_01JYDG3BK5XX0VAQN6ABY567GG/filepath_tests/exe/myclang
[/Users/runner/work/v/v/你好 my $path, @с интервали/vlib/os/find_abs_path_of_executable_test.v:35] os.real_path(myclang_file): /private/tmp/v_501/tsession_1eee5cf80_01JYDG3BK5XX0VAQN6ABY567GG/filepath_tests/exe/myclang
[/Users/runner/work/v/v/你好 my $path, @с интервали/vlib/os/find_abs_path_of_executable_test.v:36] os.is_executable(myclang_file): true
[/Users/runner/work/v/v/你好 my $path, @с интервали/vlib/os/find_abs_path_of_executable_test.v:45] os.abs_path(mylink_file): /tmp/v_501/tsession_1eee5cf80_01JYDG3BK5XX0VAQN6ABY567GG/filepath_tests/mylink
[/Users/runner/work/v/v/你好 my $path, @с интервали/vlib/os/find_abs_path_of_executable_test.v:46] os.real_path(mylink_file): /private/tmp/v_501/tsession_1eee5cf80_01JYDG3BK5XX0VAQN6ABY567GG/filepath_tests/exe/myclang
[/Users/runner/work/v/v/你好 my $path, @с интервали/vlib/os/find_abs_path_of_executable_test.v:47] os.is_executable(mylink_file): true
[/Users/runner/work/v/v/你好 my $path, @с интервали/vlib/os/find_abs_path_of_executable_test.v:70] fpath: /tmp/v_501/tsession_1eee5cf80_01JYDG3BK5XX0VAQN6ABY567GG/filepath_tests/exe/myclang
[/Users/runner/work/v/v/你好 my $path, @с интервали/vlib/os/find_abs_path_of_executable_test.v:70] fpath: /private/tmp/v_501/tsession_1eee5cf80_01JYDG3BK5XX0VAQN6ABY567GG/filepath_tests/mylink
/Users/runner/work/v/v/你好 my $path, @с интервали/vlib/os/find_abs_path_of_executable_test.v:53: fn test_find_abs_path_of_executable
  > assert find_and_check('mylink') == mylink_file
    Left value (len: 86):
      `/private/tmp/v_501/tsession_1eee5cf80_01JYDG3BK5XX0VAQN6ABY567GG/filepath_tests/mylink`
    Right value (len: 78):
      `/tmp/v_501/tsession_1eee5cf80_01JYDG3BK5XX0VAQN6ABY567GG/filepath_tests/mylink`

Definitely unexpected...

@spytheman
Copy link
Member

I believe the "Ensure code is well formatted" should be in a separate, dedicated workflow. That way it's clear right away what the problem is and only one test fails.

It is deliberately put at the start of all time consuming jobs, to save CI time, for code that is not even formatted. Many people are sloppy, and having the CI run sanitized jobs that each take 2-3 hours, results in a very long CI queue, given that often there are 3-4 active PRs with new commits in them...

@spytheman
Copy link
Member

Use cp cmd/tools/git_pre_commit_hook.vsh .git/hooks/pre-commit run on top of your V repo, to make sure, that all changed code is formatted.

@spytheman
Copy link
Member

spytheman commented Jun 23, 2025

On macos:

0[10:32:58]@m1: (master) /opt/v $ ls -la /tmp
lrwxr-xr-x@ 1 root  wheel  11  4 Май 08:39 /tmp -> private/tmp

Imho use const tfolder = os.join_path(os.real_path(os.vtmp_dir()), 'filepath_tests') .

@davidebeatrici
Copy link
Contributor Author

I'm going to wait for the checks to finish before finalizing the PR.

It is deliberately put at the start of all time consuming jobs, to save CI time, for code that is not even formatted. Many people are sloppy, and having the CI run sanitized jobs that each take 2-3 hours, results in a very long CI queue, given that often there are 3-4 active PRs with new commits in them...

Makes sense, I didn't know the heavy jobs took so long.

Use cp cmd/tools/git_pre_commit_hook.vsh .git/hooks/pre-commit run on top of your V repo, to make sure, that all changed code is formatted.

Oh, cool!

@Krzmbrzl @Hartmnt We could implement something similar in our project(s).

This fixes aliases and wrappers being ignored.

Resolving the symlinks can cause breakage, an example is coreutils:
commands such as "echo" are just a symlink to a single binary.
The name of the symlink tells the program which tool is requested.

Or even worse, in the case of security helpers such as firejail:
a symlink is created in one of the top priority folders in PATH,
so that firejail steps in and knows what to run.
Resolving the symlink would make the program run outside a jail!
Also, the code is refactored to use testsuite_begin() and testsuite_end().
@davidebeatrici davidebeatrici force-pushed the timeout-coreutils-fix branch from fd13050 to 93d6a6f Compare June 23, 2025 19:31
@davidebeatrici davidebeatrici marked this pull request as ready for review June 23, 2025 19:32
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit 1c5a9e1 into vlang:master Jun 23, 2025
75 checks passed
@davidebeatrici davidebeatrici deleted the timeout-coreutils-fix branch June 24, 2025 23:35
@davidebeatrici
Copy link
Contributor Author

Thank you for your review!

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

Successfully merging this pull request may close these issues.

"timeout" command failing
2 participants