mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #79254: getenv() w/o arguments not showing changes
This commit is contained in:
commit
93b183ed55
3 changed files with 68 additions and 24 deletions
3
NEWS
3
NEWS
|
@ -22,6 +22,9 @@ PHP NEWS
|
|||
and unicode). (Nikita)
|
||||
. Fixed bug #79241 (Segmentation fault on preg_match()). (Nikita)
|
||||
|
||||
- Standard:
|
||||
. Fixed bug #79254 (getenv() w/o arguments not showing changes). (cmb)
|
||||
|
||||
?? ??? ????, PHP 7.4.3
|
||||
|
||||
- Core:
|
||||
|
|
22
ext/standard/tests/general_functions/bug79254.phpt
Normal file
22
ext/standard/tests/general_functions/bug79254.phpt
Normal file
|
@ -0,0 +1,22 @@
|
|||
--TEST--
|
||||
Bug #79254 (getenv() w/o arguments not showing changes)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$old = getenv();
|
||||
var_dump(getenv("PHP_BUG_79254", true));
|
||||
|
||||
putenv("PHP_BUG_79254=BAR");
|
||||
|
||||
$new = getenv();
|
||||
var_dump(array_diff($new, $old));
|
||||
var_dump(getenv("PHP_BUG_79254", true));
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(false)
|
||||
array(1) {
|
||||
["PHP_BUG_79254"]=>
|
||||
string(3) "BAR"
|
||||
}
|
||||
string(3) "BAR"
|
|
@ -540,24 +540,21 @@ static zend_always_inline int valid_environment_name(const char *name, const cha
|
|||
return 1;
|
||||
}
|
||||
|
||||
void _php_import_environment_variables(zval *array_ptr)
|
||||
static zend_always_inline void import_environment_variable(HashTable *ht, char *env)
|
||||
{
|
||||
char **env, *p;
|
||||
char *p;
|
||||
size_t name_len, len;
|
||||
zval val;
|
||||
zend_ulong idx;
|
||||
|
||||
tsrm_env_lock();
|
||||
|
||||
for (env = environ; env != NULL && *env != NULL; env++) {
|
||||
p = strchr(*env, '=');
|
||||
p = strchr(env, '=');
|
||||
if (!p
|
||||
|| p == *env
|
||||
|| !valid_environment_name(*env, p)) {
|
||||
|| p == env
|
||||
|| !valid_environment_name(env, p)) {
|
||||
/* malformed entry? */
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
name_len = p - *env;
|
||||
name_len = p - env;
|
||||
p++;
|
||||
len = strlen(p);
|
||||
if (len == 0) {
|
||||
|
@ -567,13 +564,35 @@ void _php_import_environment_variables(zval *array_ptr)
|
|||
} else {
|
||||
ZVAL_NEW_STR(&val, zend_string_init(p, len, 0));
|
||||
}
|
||||
if (ZEND_HANDLE_NUMERIC_STR(*env, name_len, idx)) {
|
||||
zend_hash_index_update(Z_ARRVAL_P(array_ptr), idx, &val);
|
||||
if (ZEND_HANDLE_NUMERIC_STR(env, name_len, idx)) {
|
||||
zend_hash_index_update(ht, idx, &val);
|
||||
} else {
|
||||
php_register_variable_quick(*env, name_len, &val, Z_ARRVAL_P(array_ptr));
|
||||
php_register_variable_quick(env, name_len, &val, ht);
|
||||
}
|
||||
}
|
||||
|
||||
void _php_import_environment_variables(zval *array_ptr)
|
||||
{
|
||||
#ifndef PHP_WIN32
|
||||
char **env;
|
||||
#else
|
||||
char *environment, *env;
|
||||
#endif
|
||||
|
||||
tsrm_env_lock();
|
||||
|
||||
#ifndef PHP_WIN32
|
||||
for (env = environ; env != NULL && *env != NULL; env++) {
|
||||
import_environment_variable(Z_ARRVAL_P(array_ptr), *env);
|
||||
}
|
||||
#else
|
||||
environment = GetEnvironmentStringsA();
|
||||
for (env = environment; env != NULL && *env; env += strlen(env) + 1) {
|
||||
import_environment_variable(Z_ARRVAL_P(array_ptr), env);
|
||||
}
|
||||
FreeEnvironmentStringsA(environment);
|
||||
#endif
|
||||
|
||||
tsrm_env_unlock();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue