From: Dmitry Stogov Date: Mon, 9 Feb 2009 09:20:46 +0000 (+0000) Subject: Fixed bug #47320 ($php_errormsg out of scope in functions) X-Git-Tag: php-5.4.0alpha1~191^2~4314 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15b5f9a8c7372a86c8829800e0327ff98ee8ae8f;p=php Fixed bug #47320 ($php_errormsg out of scope in functions) --- diff --git a/Zend/tests/bug47320.phpt b/Zend/tests/bug47320.phpt new file mode 100644 index 0000000000..47db35edac --- /dev/null +++ b/Zend/tests/bug47320.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #47320 ($php_errormsg out of scope in functions) +--INI-- +display_errors=0 +track_errors=1 +--FILE-- + +--EXPECT-- +$php_errormsg in global: substr() expects at least 2 parameters, 1 given +$php_errormsg in function: strpos() expects at least 2 parameters, 1 given +$GLOBALS[php_errormsg] in function: substr() expects at least 2 parameters, 1 given diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index 53873b16e8..0851aa1c20 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -1785,15 +1785,15 @@ ZEND_API void zend_rebuild_symbol_table(TSRMLS_D) /* {{{ */ return; } - if (EG(symtable_cache_ptr)>=EG(symtable_cache)) { - /*printf("Cache hit! Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/ - EG(active_symbol_table) = *(EG(symtable_cache_ptr)--); - } else { - ALLOC_HASHTABLE(EG(active_symbol_table)); - zend_hash_init(EG(active_symbol_table), 0, NULL, ZVAL_PTR_DTOR, 0); - /*printf("Cache miss! Initialized %x\n", EG(active_symbol_table));*/ - } if (ex && ex->op_array) { + if (EG(symtable_cache_ptr)>=EG(symtable_cache)) { + /*printf("Cache hit! Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/ + EG(active_symbol_table) = *(EG(symtable_cache_ptr)--); + } else { + ALLOC_HASHTABLE(EG(active_symbol_table)); + zend_hash_init(EG(active_symbol_table), 0, NULL, ZVAL_PTR_DTOR, 0); + /*printf("Cache miss! Initialized %x\n", EG(active_symbol_table));*/ + } ex->symbol_table = EG(active_symbol_table); if (ex->op_array->this_var != -1 && diff --git a/main/main.c b/main/main.c index 4b3965f570..5dd7dad75e 100644 --- a/main/main.c +++ b/main/main.c @@ -853,12 +853,17 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c php_error(type, "%s", message); efree(message); - if (PG(track_errors) && module_initialized && EG(active_symbol_table) && + if (PG(track_errors) && module_initialized && (!EG(user_error_handler) || !(EG(user_error_handler_error_reporting) & type))) { - zval *tmp; - ALLOC_INIT_ZVAL(tmp); - ZVAL_RT_STRINGL(tmp, buffer, buffer_len, 1); - zend_ascii_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) &tmp, sizeof(zval *), NULL); + if (!EG(active_symbol_table)) { + zend_rebuild_symbol_table(TSRMLS_C); + } + if (EG(active_symbol_table)) { + zval *tmp; + ALLOC_INIT_ZVAL(tmp); + ZVAL_RT_STRINGL(tmp, buffer, buffer_len, 1); + zend_ascii_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) &tmp, sizeof(zval *), NULL); + } } efree(buffer); } @@ -1125,12 +1130,17 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ efree(buffer); return; } - if (PG(track_errors) && module_initialized && EG(active_symbol_table)) { - zval *tmp; + if (PG(track_errors) && module_initialized) { + if (!EG(active_symbol_table)) { + zend_rebuild_symbol_table(TSRMLS_C); + } + if (EG(active_symbol_table)) { + zval *tmp; - ALLOC_INIT_ZVAL(tmp); - ZVAL_RT_STRINGL(tmp, buffer, buffer_len, 1); - zend_ascii_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(zval *), NULL); + ALLOC_INIT_ZVAL(tmp); + ZVAL_RT_STRINGL(tmp, buffer, buffer_len, 1); + zend_ascii_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(zval *), NULL); + } } efree(buffer); }