Skip to content

Commit 3defaed

Browse files
committed
do not search in $PATH entries not allowed by open_basedir
1 parent 5d0fa8e commit 3defaed

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

src/Symfony/Component/Process/ExecutableFinder.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,23 @@ public function addSuffix(string $suffix)
4848
*/
4949
public function find(string $name, ?string $default = null, array $extraDirs = [])
5050
{
51+
$dirs = array_merge(
52+
explode(\PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
53+
$extraDirs
54+
);
55+
5156
if (\ini_get('open_basedir')) {
5257
$searchPath = array_merge(explode(\PATH_SEPARATOR, \ini_get('open_basedir')), $extraDirs);
53-
$dirs = [];
58+
foreach ($dirs as $index => $dir) {
59+
foreach ($searchPath as $path) {
60+
if (str_starts_with($dir, $path)) {
61+
continue 2;
62+
}
63+
}
64+
65+
unset($dirs[$index]);
66+
}
67+
5468
foreach ($searchPath as $path) {
5569
// Silencing against https://bugs.php.net/69240
5670
if (@is_dir($path)) {
@@ -61,11 +75,6 @@ public function find(string $name, ?string $default = null, array $extraDirs = [
6175
}
6276
}
6377
}
64-
} else {
65-
$dirs = array_merge(
66-
explode(\PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
67-
$extraDirs
68-
);
6978
}
7079

7180
$suffixes = [''];

src/Symfony/Component/Process/Tests/ExecutableFinderTest.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,43 @@ public function testFindWithOpenBaseDir()
109109
$this->markTestSkipped('Cannot test when open_basedir is set');
110110
}
111111

112-
$initialOpenBaseDir = ini_set('open_basedir', \dirname(\PHP_BINARY).\PATH_SEPARATOR.'/');
112+
$initialOpenBaseDir = ini_set('open_basedir', \dirname(\PHP_BINARY).\PATH_SEPARATOR.sys_get_temp_dir().\PATH_SEPARATOR.getcwd());
113113

114114
try {
115115
$finder = new ExecutableFinder();
116116
$result = $finder->find($this->getPhpBinaryName());
117-
118117
$this->assertSamePath(\PHP_BINARY, $result);
119118
} finally {
120119
ini_set('open_basedir', $initialOpenBaseDir);
121120
}
122121
}
123122

123+
/**
124+
* @runInSeparateProcess
125+
*/
126+
public function testFindWithSubdirectoryOfOpenBaseDir()
127+
{
128+
if (\ini_get('open_basedir')) {
129+
$this->markTestSkipped('Cannot test when open_basedir is set');
130+
}
131+
132+
$paths = explode(\PATH_SEPARATOR, getenv('PATH'));
133+
$phpBinaryPath = \dirname(\PHP_BINARY);
134+
135+
if (!in_array($phpBinaryPath, $paths, true)) {
136+
$paths[] = $phpBinaryPath;
137+
}
138+
139+
$this->setPath(implode(\PATH_SEPARATOR, $paths));
140+
141+
ini_set('open_basedir', \dirname(\dirname(\PHP_BINARY)).\PATH_SEPARATOR.sys_get_temp_dir().\PATH_SEPARATOR.getcwd());
142+
143+
$finder = new ExecutableFinder();
144+
$result = $finder->find($this->getPhpBinaryName());
145+
146+
$this->assertSamePath(\PHP_BINARY, $result);
147+
}
148+
124149
/**
125150
* @runInSeparateProcess
126151
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy