Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 63be6fa

Browse filesBrowse files
committed
bug #45676 [Process] Don't return executable directories in PhpExecutableFinder (fancyweb)
This PR was merged into the 4.4 branch. Discussion ---------- [Process] Don't return executable directories in PhpExecutableFinder | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #45620 | License | MIT | Doc PR | - Directories can be executable and be wrongly returned if some env vars have directory paths as their values. Commits ------- 947152b [Process] Don't return executable directories in PhpExecutableFinder
2 parents c55ff99 + 947152b commit 63be6fa
Copy full SHA for 63be6fa

File tree

Expand file treeCollapse file tree

2 files changed

+32
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+32
-8
lines changed

‎src/Symfony/Component/Process/PhpExecutableFinder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/PhpExecutableFinder.php
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public function find($includeArgs = true)
4747
}
4848
}
4949

50+
if (@is_dir($php)) {
51+
return false;
52+
}
53+
5054
return $php;
5155
}
5256

@@ -59,20 +63,20 @@ public function find($includeArgs = true)
5963
}
6064

6165
if ($php = getenv('PHP_PATH')) {
62-
if (!@is_executable($php)) {
66+
if (!@is_executable($php) || @is_dir($php)) {
6367
return false;
6468
}
6569

6670
return $php;
6771
}
6872

6973
if ($php = getenv('PHP_PEAR_PHP_BIN')) {
70-
if (@is_executable($php)) {
74+
if (@is_executable($php) && !@is_dir($php)) {
7175
return $php;
7276
}
7377
}
7478

75-
if (@is_executable($php = \PHP_BINDIR.('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php'))) {
79+
if (@is_executable($php = \PHP_BINDIR.('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php')) && !@is_dir($php)) {
7680
return $php;
7781
}
7882

‎src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php
+25-5Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,32 @@ public function testFindArguments()
5050
public function testNotExitsBinaryFile()
5151
{
5252
$f = new PhpExecutableFinder();
53-
$phpBinaryEnv = \PHP_BINARY;
54-
putenv('PHP_BINARY=/usr/local/php/bin/php-invalid');
5553

56-
$this->assertFalse($f->find(), '::find() returns false because of not exist file');
57-
$this->assertFalse($f->find(false), '::find(false) returns false because of not exist file');
54+
$originalPhpBinary = getenv('PHP_BINARY');
5855

59-
putenv('PHP_BINARY='.$phpBinaryEnv);
56+
try {
57+
putenv('PHP_BINARY=/usr/local/php/bin/php-invalid');
58+
59+
$this->assertFalse($f->find(), '::find() returns false because of not exist file');
60+
$this->assertFalse($f->find(false), '::find(false) returns false because of not exist file');
61+
} finally {
62+
putenv('PHP_BINARY='.$originalPhpBinary);
63+
}
64+
}
65+
66+
public function testFindWithExecutableDirectory()
67+
{
68+
$originalPhpBinary = getenv('PHP_BINARY');
69+
70+
try {
71+
$executableDirectoryPath = sys_get_temp_dir().'/PhpExecutableFinderTest_testFindWithExecutableDirectory';
72+
@mkdir($executableDirectoryPath);
73+
$this->assertTrue(is_executable($executableDirectoryPath));
74+
putenv('PHP_BINARY='.$executableDirectoryPath);
75+
76+
$this->assertFalse((new PhpExecutableFinder())->find());
77+
} finally {
78+
putenv('PHP_BINARY='.$originalPhpBinary);
79+
}
6080
}
6181
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.