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

Process tasks can attempt to execute directories on Linux #158914

Closed
tobil4sk opened this issue Aug 23, 2022 · 4 comments · Fixed by #228373
Closed

Process tasks can attempt to execute directories on Linux #158914

tobil4sk opened this issue Aug 23, 2022 · 4 comments · Fixed by #228373
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders tasks Task system issues verified Verification succeeded
Milestone

Comments

@tobil4sk
Copy link
Contributor

tobil4sk commented Aug 23, 2022

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.70.2
  • OS Version: Linux x64 5.19.2-1-MANJARO

Steps to Reproduce:

  1. Install an extension with "process" tasks which run executables from PATH, e.g. this minimal extension running python
  2. Create a folder in the first PATH entry with the same name as the executable, e.g. ~/.local/bin/python
  3. Attempt to execute the task, and receive this error:
 *  Executing task: python

execvp(3) failed.: Permission denied

 *  The terminal process "python" failed to launch (exit code: 1). 
 *  Terminal will be reused by tasks, press any key to close it.

This is because the default function used by the findExecutable function does not check whether something is a file or a directory, but only that it exists:

export async function findExecutable(command: string, cwd?: string, paths?: string[], env: IProcessEnvironment = process.env as IProcessEnvironment, exists: (path: string) => Promise<boolean> = pfs.Promises.exists): Promise<string | undefined> {

This was fixed for win32.findExecutable in 9bc292a and 52daded, where directories are ignored when searching PATH. However, as these functions are in separate files, the other one missed out on this fix.

Ideally these two functions should be merged as they perform pretty much the same job, and it would avoid this problem in the future. It might be worth considering making task behaviour consistent between platforms in terms of at which point executable paths are resolved, as that seems to be why we ended up with two implementations in the first place.

@gjsjohnmurray
Copy link
Contributor

Maybe related to #158666

@meganrogge meganrogge added the tasks Task system issues label Aug 23, 2022
@tobil4sk
Copy link
Contributor Author

#158666 is somewhat related, however, the two issues come from separate parts of the code. This problem comes from the findExecutable function.

The PR will somewhat improve the situation, because this error will be caught slightly earlier, so it will say: The terminal process failed to launch: Path to shell executable "python" is not a file or a symlink.. However, the expected behaviour is that there should be no error if a valid executable exists, regardless of any directories in PATH.

@meganrogge meganrogge added this to the September 2022 milestone Aug 31, 2022
@Tyriar Tyriar modified the milestones: September 2022, Backlog Sep 26, 2022
@meganrogge meganrogge added bug Issue identified by VS Code Team member as probable bug confirmation-pending labels Dec 5, 2022
@kLabz
Copy link

kLabz commented Sep 12, 2024

Any news on this? Vscode currently doesn't follow usual executable resolution which can be really confusing for users.

@tobil4sk
Copy link
Contributor Author

Slightly simpler reproduction instructions:

  • create a python directory in the first PATH entry, e.g. ~/.local/bin/python
  • ensure python executable exists somewhere else in PATH.
  • launch vscode
  • create this .vscode/tasks.json file:
{
	"version": "2.0.0",
	"tasks": [
		{
			"label": "run python",
			"type": "process",
			"command": "python",
			"args": ["--version"],
			"problemMatcher": []
		}
	]
}
  • Tasks: Run Task, run python

Expected behaviour: python version is printed
Actual behaviour: The terminal process failed to launch: Path to shell executable "python" is not a file or a symlink.

I've opened a PR with a patch: #228373.

@meganrogge meganrogge modified the milestones: Backlog, October 2024 Sep 13, 2024
@rzhao271 rzhao271 modified the milestones: October 2024, November 2024 Oct 21, 2024
@bpasero bpasero removed their assignment Oct 22, 2024
@rzhao271 rzhao271 modified the milestones: November 2024, January 2025 Nov 27, 2024
@vs-code-engineering vs-code-engineering bot added unreleased Patch has not yet been released in VS Code Insiders insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Dec 11, 2024
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Jan 25, 2025
@DonJayamanne DonJayamanne added the verified Verification succeeded label Jan 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders tasks Task system issues verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants