Skip to content

Commit

Permalink
Merge branch 'PHP-8.0' into PHP-8.1
Browse files Browse the repository at this point in the history
* PHP-8.0:
  Fix GH-7896: Environment vars may be mangled on Windows
  • Loading branch information
cmb69 committed Jan 17, 2022
2 parents 79bf39e + 93a3c71 commit 8d2ed19
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -5,6 +5,7 @@ PHP NEWS
- Core:
. Fixed bug #81430 (Attribute instantiation leaves dangling pointer).
(beberlei)
. Fixed bug GH-7896 (Environment vars may be mangled on Windows). (cmb)

- FFI:
. Fixed bug GH-7867 (FFI::cast() from pointer to array is broken). (cmb,
Expand Down
12 changes: 8 additions & 4 deletions main/php_variables.c
Expand Up @@ -571,11 +571,15 @@ void _php_import_environment_variables(zval *array_ptr)
import_environment_variable(Z_ARRVAL_P(array_ptr), *env);
}
#else
char *environment = GetEnvironmentStringsA();
for (char *env = environment; env != NULL && *env; env += strlen(env) + 1) {
import_environment_variable(Z_ARRVAL_P(array_ptr), env);
wchar_t *environmentw = GetEnvironmentStringsW();
for (wchar_t *envw = environmentw; envw != NULL && *envw; envw += wcslen(envw) + 1) {
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

tsrm_env_unlock();
Expand Down
20 changes: 20 additions & 0 deletions tests/basic/gh7896.phpt
@@ -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传"

0 comments on commit 8d2ed19

Please sign in to comment.