diff --git a/src/Symfony/Component/Process/ExecutableFinder.php b/src/Symfony/Component/Process/ExecutableFinder.php index 2fe558be95c5f..6ad847db9a303 100644 --- a/src/Symfony/Component/Process/ExecutableFinder.php +++ b/src/Symfony/Component/Process/ExecutableFinder.php @@ -46,10 +46,19 @@ public function addSuffix(string $suffix) */ public function find(string $name, string $default = null, array $extraDirs = []): ?string { + $command = strtok(exec(('\\' === \DIRECTORY_SEPARATOR ? 'where ' : 'command -v ').escapeshellarg($name)), \PHP_EOL); + if ($command && !@is_executable($command)) { + $command = null; + } + if (ini_get('open_basedir')) { $searchPath = array_merge(explode(\PATH_SEPARATOR, ini_get('open_basedir')), $extraDirs); $dirs = []; foreach ($searchPath as $path) { + if ($command && 0 === \strpos($command, $path)) { + return $command; + } + // Silencing against https://bugs.php.net/69240 if (@is_dir($path)) { $dirs[] = $path; @@ -59,6 +68,8 @@ public function find(string $name, string $default = null, array $extraDirs = [] } } } + } elseif ($command) { + return $command; } else { $dirs = array_merge( explode(\PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),