Skip to content

Commit bb18d53

Browse files
author
Sébastien HOUZÉ
authored
fix: thread safety regarding env vars (#633)
Fix: #632
1 parent 2ae30f2 commit bb18d53

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ public static function create(array $options)
9393
foreach ($fallbackGroup as $option => $envVariableNames) {
9494
$envVariableNames = (array) $envVariableNames;
9595
foreach ($envVariableNames as $envVariableName) {
96-
if (false !== $value = \getenv($envVariableName)) {
97-
$options[$option] = $value;
96+
if (isset($_SERVER[$envVariableName])) {
97+
$options[$option] = $_SERVER[$envVariableName];
9898

9999
break;
100100
}

src/Credentials/IniFileLoader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ public function loadProfiles(array $filepaths): array
6565
private function getHomeDir(): string
6666
{
6767
// On Linux/Unix-like systems, use the HOME environment variable
68-
if (false !== $homeDir = \getenv('HOME')) {
68+
if (\is_string($homeDir = $_SERVER['HOME'] ?? null)) {
6969
return $homeDir;
7070
}
7171

7272
// Get the HOMEDRIVE and HOMEPATH values for Windows hosts
73-
$homeDrive = \getenv('HOMEDRIVE');
74-
$homePath = \getenv('HOMEPATH');
73+
$homeDrive = $_SERVER['HOMEDRIVE'] ?? null;
74+
$homePath = $_SERVER['HOMEPATH'] ?? null;
7575

7676
return ($homeDrive && $homePath) ? $homeDrive . $homePath : '/';
7777
}

tests/Unit/ConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ConfigurationTest extends TestCase
1515
public function testCreate($config, $env, $expected)
1616
{
1717
foreach ($env as $key => $value) {
18-
putenv("$key=$value");
18+
$_SERVER[$key] = $value;
1919
}
2020

2121
try {
@@ -25,7 +25,7 @@ public function testCreate($config, $env, $expected)
2525
}
2626
} finally {
2727
foreach ($env as $key => $value) {
28-
putenv($key);
28+
unset($_SERVER[$key]);
2929
}
3030
}
3131
}

0 commit comments

Comments
 (0)