Skip to content

Commit ca79b6e

Browse files
[Lock][Process] Replace strtok calls
1 parent 6f5cb98 commit ca79b6e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

ExecutableFinder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,14 @@ public function find(string $name, ?string $default = null, array $extraDirs = [
7979
}
8080
}
8181

82+
if (!\function_exists('exec')) {
83+
return $default;
84+
}
85+
8286
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v --';
83-
if (\function_exists('exec') && ($executablePath = strtok(@exec($command.' '.escapeshellarg($name)), \PHP_EOL)) && @is_executable($executablePath)) {
87+
$execResult = @exec($command.' '.escapeshellarg($name));
88+
89+
if (($executablePath = substr($execResult, 0, strpos($execResult, \PHP_EOL) ?: null)) && @is_executable($executablePath)) {
8490
return $executablePath;
8591
}
8692

PhpExecutableFinder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ public function find(bool $includeArgs = true): string|false
3333
{
3434
if ($php = getenv('PHP_BINARY')) {
3535
if (!is_executable($php)) {
36+
if (!\function_exists('exec')) {
37+
return false;
38+
}
39+
3640
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v --';
37-
if (\function_exists('exec') && $php = strtok(exec($command.' '.escapeshellarg($php)), \PHP_EOL)) {
41+
$execResult = exec($command.' '.escapeshellarg($php));
42+
if ($php = substr($execResult, 0, strpos($execResult, \PHP_EOL) ?: null)) {
3843
if (!is_executable($php)) {
3944
return false;
4045
}

0 commit comments

Comments
 (0)