From 023c8a7d95e7b39c47ac4d891a930873bf49f0db Mon Sep 17 00:00:00 2001 From: Zeev Suraski Date: Mon, 21 Jul 2003 17:42:24 +0000 Subject: [PATCH] Fix register_globals --- main/php_variables.c | 49 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/main/php_variables.c b/main/php_variables.c index 2877d4dc4d..49d9d0aad5 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -493,6 +493,41 @@ static inline void php_register_server_variables(TSRMLS_D) /* }}} */ + +/* {{{ php_autoglobal_merge + */ +static void php_autoglobal_merge(HashTable *dest, HashTable *src TSRMLS_DC) +{ + zval **src_entry, **dest_entry; + char *string_key; + uint string_key_len; + ulong num_key; + HashPosition pos; + int key_type; + + zend_hash_internal_pointer_reset_ex(src, &pos); + while (zend_hash_get_current_data_ex(src, (void **)&src_entry, &pos) == SUCCESS) { + key_type = zend_hash_get_current_key_ex(src, &string_key, &string_key_len, &num_key, 0, &pos); + if (Z_TYPE_PP(src_entry) != IS_ARRAY || + (string_key_len && zend_hash_find(dest, string_key, string_key_len, (void **)&dest_entry) != SUCCESS) || + (!string_key_len && zend_hash_index_find(dest, num_key, (void **)&dest_entry) != SUCCESS) + || Z_TYPE_PP(dest_entry) != IS_ARRAY) { + (*src_entry)->refcount++; + if (key_type == HASH_KEY_IS_STRING) { + zend_hash_update(dest, string_key, strlen(string_key)+1, src_entry, sizeof(zval *), NULL); + } else { + zend_hash_index_update(dest, num_key, src_entry, sizeof(zval *), NULL); + } + } else { + SEPARATE_ZVAL(dest_entry); + php_autoglobal_merge(Z_ARRVAL_PP(dest_entry), Z_ARRVAL_PP(src_entry) TSRMLS_CC); + } + zend_hash_move_forward_ex(src, &pos); + } +} +/* }}} */ + + static zend_bool php_auto_globals_create_server(char *name, uint name_len TSRMLS_DC); static zend_bool php_auto_globals_create_env(char *name, uint name_len TSRMLS_DC); static zend_bool php_auto_globals_create_request(char *name, uint name_len TSRMLS_DC); @@ -588,6 +623,14 @@ int php_hash_environment(TSRMLS_D) php_register_server_variables(TSRMLS_C); } + if (PG(register_globals)) { + for (i = 0; i < 5; i++) { + if (PG(http_globals)[i]) { + php_autoglobal_merge(&EG(symbol_table), Z_ARRVAL_P(PG(http_globals)[i]) TSRMLS_CC); + } + } + } + for (i=0; i