Skip to content

File::getExecutablePath()` returns directory instead of executable #5210

@aleks-f

Description

@aleks-f

File::getExecutablePath() returns directory instead of executable when CWD contains same-named directory

Problem

getExecutablePathImpl() on UNIX uses findInPath() to resolve bare command names. findInPath() checks CWD first using File::exists(), which returns true for directories. If a directory in the current working directory has the same name as an executable on PATH, getExecutablePathImpl() returns the directory path instead of continuing the search.

This causes ProcessRunner to fail with "command not found" when the working directory happens to contain a same-named directory (e.g. a source checkout named crun/ shadowing /usr/bin/crun).

Root Cause

findInPath() returns the first existing entry — it has no way to skip directories and continue searching. The S_ISREG check in getExecutablePathImpl() correctly rejects the directory, but then falls through to return {} with no fallback to continue the PATH search.

Fix

Replace the findInPath() call in the bare-name branch of getExecutablePathImpl() with an inline CWD + PATH search that uses an isExecutableFile lambda checking both S_ISREG and executable permission bits. This skips directories and non-executable files, continuing to the next PATH entry.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions