mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Fix GH-7896: Environment vars may be mangled on Windows
When bug 77574[1] has been fixed, the fix only catered to variables retrieved via `getenv()` with a `$varname` passed, but neither to `getenv()` without arguments nor to the general import of environment variables into `$_ENV` and `$_SERVER`. We catch up on this by using `GetEnvironmentStringsW()` in `_php_import_environment_variables()` and converting the encoding to whatever had been chosen by the user. [1] <https://bugs.php.net/bug.php?id=75574> Closes GH-7928.
This commit is contained in:
parent
478edcdacb
commit
93a3c71eb4
3 changed files with 29 additions and 4 deletions
1
NEWS
1
NEWS
|
@ -5,6 +5,7 @@ PHP NEWS
|
||||||
- Core:
|
- Core:
|
||||||
. Fixed bug #81430 (Attribute instantiation leaves dangling pointer).
|
. Fixed bug #81430 (Attribute instantiation leaves dangling pointer).
|
||||||
(beberlei)
|
(beberlei)
|
||||||
|
. Fixed bug GH-7896 (Environment vars may be mangled on Windows). (cmb)
|
||||||
|
|
||||||
- FFI:
|
- FFI:
|
||||||
. Fixed bug GH-7867 (FFI::cast() from pointer to array is broken). (cmb,
|
. Fixed bug GH-7867 (FFI::cast() from pointer to array is broken). (cmb,
|
||||||
|
|
|
@ -571,11 +571,15 @@ void _php_import_environment_variables(zval *array_ptr)
|
||||||
import_environment_variable(Z_ARRVAL_P(array_ptr), *env);
|
import_environment_variable(Z_ARRVAL_P(array_ptr), *env);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
char *environment = GetEnvironmentStringsA();
|
wchar_t *environmentw = GetEnvironmentStringsW();
|
||||||
for (char *env = environment; env != NULL && *env; env += strlen(env) + 1) {
|
for (wchar_t *envw = environmentw; envw != NULL && *envw; envw += wcslen(envw) + 1) {
|
||||||
import_environment_variable(Z_ARRVAL_P(array_ptr), env);
|
char *env = php_win32_cp_w_to_any(envw);
|
||||||
|
if (env != NULL) {
|
||||||
|
import_environment_variable(Z_ARRVAL_P(array_ptr), env);
|
||||||
|
free(env);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FreeEnvironmentStringsA(environment);
|
FreeEnvironmentStringsW(environmentw);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tsrm_env_unlock();
|
tsrm_env_unlock();
|
||||||
|
|
20
tests/basic/gh7896.phpt
Normal file
20
tests/basic/gh7896.phpt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
--TEST--
|
||||||
|
GH-7896 (Environment vars may be mangled on Windows)
|
||||||
|
--SKIPIF--
|
||||||
|
<?php
|
||||||
|
if (PHP_OS_FAMILY !== "Windows") die("skip for Windows only");
|
||||||
|
?>
|
||||||
|
--ENV--
|
||||||
|
FÖÖ=GüИter传
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
var_dump(
|
||||||
|
$_SERVER['FÖÖ'],
|
||||||
|
$_ENV['FÖÖ'],
|
||||||
|
getenv('FÖÖ')
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(11) "GüИter传"
|
||||||
|
string(11) "GüИter传"
|
||||||
|
string(11) "GüИter传"
|
Loading…
Add table
Add a link
Reference in a new issue