diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2020-02-11 12:07:19 +0100 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2020-02-11 12:08:25 +0100 |
commit | 69819baee34f24e42305516e61fdc7e61593a3bb (patch) | |
tree | 5feae6ffbfe998506e4e5bc53b9fa485d9c9758d /main/php_variables.c | |
parent | 8ceac81b45c591c498b44faaf002f9e2e2def7c1 (diff) | |
parent | 93b183ed551999e8c3f80cff1cc40c2be5f33033 (diff) | |
download | php-git-69819baee34f24e42305516e61fdc7e61593a3bb.tar.gz |
Merge branch 'PHP-7.4'
* PHP-7.4:
Fix #79254: getenv() w/o arguments not showing changes
Diffstat (limited to 'main/php_variables.c')
-rw-r--r-- | main/php_variables.c | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/main/php_variables.c b/main/php_variables.c index 8edbcac628..6fb6ca000d 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -538,39 +538,52 @@ 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; + p = strchr(env, '='); + if (!p + || p == env + || !valid_environment_name(env, p)) { + /* malformed entry? */ + return; + } + name_len = p - env; + p++; + len = strlen(p); + if (len == 0) { + ZVAL_EMPTY_STRING(&val); + } else if (len == 1) { + ZVAL_INTERNED_STR(&val, ZSTR_CHAR((zend_uchar)*p)); + } else { + ZVAL_NEW_STR(&val, zend_string_init(p, len, 0)); + } + 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, ht); + } +} + +void _php_import_environment_variables(zval *array_ptr) +{ tsrm_env_lock(); - for (env = environ; env != NULL && *env != NULL; env++) { - p = strchr(*env, '='); - if (!p - || p == *env - || !valid_environment_name(*env, p)) { - /* malformed entry? */ - continue; - } - name_len = p - *env; - p++; - len = strlen(p); - if (len == 0) { - ZVAL_EMPTY_STRING(&val); - } else if (len == 1) { - ZVAL_INTERNED_STR(&val, ZSTR_CHAR((zend_uchar)*p)); - } 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); - } else { - php_register_variable_quick(*env, name_len, &val, Z_ARRVAL_P(array_ptr)); - } +#ifndef PHP_WIN32 + for (char **env = environ; env != NULL && *env != NULL; env++) { + 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); + } + FreeEnvironmentStringsA(environment); +#endif tsrm_env_unlock(); } |