-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
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.