diff options
Diffstat (limited to 'main/php_variables.c')
-rw-r--r-- | main/php_variables.c | 65 |
1 files changed, 51 insertions, 14 deletions
diff --git a/main/php_variables.c b/main/php_variables.c index 43b00d9322..a5256e7322 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2015 The PHP Group | + | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -79,7 +79,7 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars /* ignore leading spaces in the variable name */ - while (*var_name && *var_name==' ') { + while (*var_name==' ') { var_name++; } @@ -109,6 +109,26 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars return; } + if (var_len == sizeof("this")-1 && EG(current_execute_data)) { + zend_execute_data *ex = EG(current_execute_data); + + while (ex) { + if (ex->func && ZEND_USER_CODE(ex->func->common.type)) { + if ((ZEND_CALL_INFO(ex) & ZEND_CALL_HAS_SYMBOL_TABLE) + && ex->symbol_table == symtable1) { + if (memcmp(var, "this", sizeof("this")-1) == 0) { + zend_throw_error(NULL, "Cannot re-assign $this"); + zval_dtor(val); + free_alloca(var_orig, use_heap); + return; + } + } + break; + } + ex = ex->prev_execute_data; + } + } + /* GLOBALS hijack attempt, reject parameter */ if (symtable1 == &EG(symbol_table) && var_len == sizeof("GLOBALS")-1 && @@ -524,7 +544,7 @@ zend_bool php_std_auto_global_callback(char *name, uint name_len) /* {{{ php_build_argv */ -static void php_build_argv(char *s, zval *track_vars_array) +PHPAPI void php_build_argv(char *s, zval *track_vars_array) { zval arr, argc, tmp; int count = 0; @@ -592,6 +612,8 @@ static void php_build_argv(char *s, zval *track_vars_array) */ static inline void php_register_server_variables(void) { + zval request_time_float, request_time_long; + zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]); array_init(&PG(http_globals)[TRACK_VARS_SERVER]); @@ -610,15 +632,12 @@ static inline void php_register_server_variables(void) if (SG(request_info).auth_digest) { php_register_variable("PHP_AUTH_DIGEST", SG(request_info).auth_digest, &PG(http_globals)[TRACK_VARS_SERVER]); } - /* store request init time */ - { - zval request_time_float, request_time_long; - ZVAL_DOUBLE(&request_time_float, sapi_get_request_time()); - php_register_variable_ex("REQUEST_TIME_FLOAT", &request_time_float, &PG(http_globals)[TRACK_VARS_SERVER]); - ZVAL_LONG(&request_time_long, zend_dval_to_lval(Z_DVAL(request_time_float))); - php_register_variable_ex("REQUEST_TIME", &request_time_long, &PG(http_globals)[TRACK_VARS_SERVER]); - } + /* store request init time */ + ZVAL_DOUBLE(&request_time_float, sapi_get_request_time()); + php_register_variable_ex("REQUEST_TIME_FLOAT", &request_time_float, &PG(http_globals)[TRACK_VARS_SERVER]); + ZVAL_LONG(&request_time_long, zend_dval_to_lval(Z_DVAL(request_time_float))); + php_register_variable_ex("REQUEST_TIME", &request_time_long, &PG(http_globals)[TRACK_VARS_SERVER]); } /* }}} */ @@ -650,7 +669,7 @@ static void php_autoglobal_merge(HashTable *dest, HashTable *src) zend_hash_index_update(dest, num_key, src_entry); } } else { - SEPARATE_ZVAL(dest_entry); + SEPARATE_ARRAY(dest_entry); php_autoglobal_merge(Z_ARRVAL_P(dest_entry), Z_ARRVAL_P(src_entry)); } } ZEND_HASH_FOREACH_END(); @@ -731,6 +750,22 @@ static zend_bool php_auto_globals_create_files(zend_string *name) return 0; /* don't rearm */ } +/* Upgly hack to fix HTTP_PROXY issue, see bug #72573 */ +static void check_http_proxy(HashTable *var_table) +{ + if (zend_hash_str_exists(var_table, "HTTP_PROXY", sizeof("HTTP_PROXY")-1)) { + char *local_proxy = getenv("HTTP_PROXY"); + + if (!local_proxy) { + zend_hash_str_del(var_table, "HTTP_PROXY", sizeof("HTTP_PROXY")-1); + } else { + zval local_zval; + ZVAL_STRING(&local_zval, local_proxy); + zend_hash_str_update(var_table, "HTTP_PROXY", sizeof("HTTP_PROXY")-1, &local_zval); + } + } +} + static zend_bool php_auto_globals_create_server(zend_string *name) { if (PG(variables_order) && (strchr(PG(variables_order),'S') || strchr(PG(variables_order),'s'))) { @@ -740,8 +775,8 @@ static zend_bool php_auto_globals_create_server(zend_string *name) if (SG(request_info).argc) { zval *argc, *argv; - if ((argc = zend_hash_str_find(&EG(symbol_table), "argc", sizeof("argc")-1)) != NULL && - (argv = zend_hash_str_find(&EG(symbol_table), "argv", sizeof("argv")-1)) != NULL) { + if ((argc = zend_hash_str_find_ind(&EG(symbol_table), "argc", sizeof("argc")-1)) != NULL && + (argv = zend_hash_str_find_ind(&EG(symbol_table), "argv", sizeof("argv")-1)) != NULL) { Z_ADDREF_P(argv); zend_hash_str_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv")-1, argv); zend_hash_str_update(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "argc", sizeof("argc")-1, argc); @@ -756,6 +791,7 @@ static zend_bool php_auto_globals_create_server(zend_string *name) array_init(&PG(http_globals)[TRACK_VARS_SERVER]); } + check_http_proxy(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER])); zend_hash_update(&EG(symbol_table), name, &PG(http_globals)[TRACK_VARS_SERVER]); Z_ADDREF(PG(http_globals)[TRACK_VARS_SERVER]); @@ -771,6 +807,7 @@ static zend_bool php_auto_globals_create_env(zend_string *name) php_import_environment_variables(&PG(http_globals)[TRACK_VARS_ENV]); } + check_http_proxy(Z_ARRVAL(PG(http_globals)[TRACK_VARS_ENV])); zend_hash_update(&EG(symbol_table), name, &PG(http_globals)[TRACK_VARS_ENV]); Z_ADDREF(PG(http_globals)[TRACK_VARS_ENV]); |