Fixed bug #28377 (debug_backtrace is intermittently passing args)

This commit is contained in:
Dmitry Stogov 2005-06-23 12:00:13 +00:00
parent 5443879053
commit f3f97394b2
3 changed files with 54 additions and 0 deletions

1
NEWS
View File

@ -5,6 +5,7 @@ PHP NEWS
overloaded (__get)). (Dmitry)
- Fixed bug #30828 (debug_backtrace() reports incorrect class in overridden
methods). (Dmitry)
- Fixed bug #28377 (debug_backtrace is intermittently passing args). (Dmitry)
- Fixed bug #27268 (Bad references accentuated by clone). (Dmitry)
22 Jun 2005, PHP 5.1 Beta 2

23
Zend/tests/bug28377.phpt Executable file
View File

@ -0,0 +1,23 @@
--TEST--
Bug #28377 (debug_backtrace is intermittently passing args)
--FILE--
<?php
function doit($a, $b)
{
$trace = debug_backtrace();
custom_callback('dereferenced', $trace);
custom_callback('direct', debug_backtrace());
}
function custom_callback($traceName, $btInfo)
{
echo $traceName ." -- args: ";
echo isset($btInfo[0]['args']) ? count($btInfo[0]['args']) : 'does not exist';
echo "\n";
}
doit('a','b');
?>
--EXPECT--
dereferenced -- args: 2
direct -- args: 2

View File

@ -1622,6 +1622,12 @@ static zval *debug_backtrace_get_args(void ***curpos TSRMLS_DC)
(*arg)->refcount++;
add_next_index_zval(arg_array, *arg);
}
/* skip args from incomplete frames */
while ((((*curpos)-1) > EG(argument_stack).elements) && *((*curpos)-1)) {
(*curpos)--;
}
return arg_array;
}
@ -1669,6 +1675,11 @@ ZEND_FUNCTION(debug_print_backtrace)
args -= *(ulong*)args;
frames_on_stack++;
/* skip args from incomplete frames */
while (((args-1) > EG(argument_stack).elements) && *(args-1)) {
args--;
}
if ((args-1) == EG(argument_stack).elements) {
arg_stack_consistent = 1;
break;
@ -1682,6 +1693,13 @@ ZEND_FUNCTION(debug_print_backtrace)
cur_arg_pos -= 2;
frames_on_stack--;
if (arg_stack_consistent) {
/* skip args from incomplete frames */
while (((cur_arg_pos-1) > EG(argument_stack).elements) && *(cur_arg_pos-1)) {
cur_arg_pos--;
}
}
array_init(return_value);
while (ptr) {
@ -1817,6 +1835,11 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last TSRML
args -= *(ulong*)args;
frames_on_stack++;
/* skip args from incomplete frames */
while (((args-1) > EG(argument_stack).elements) && *(args-1)) {
args--;
}
if ((args-1) == EG(argument_stack).elements) {
arg_stack_consistent = 1;
break;
@ -1836,6 +1859,13 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last TSRML
cur_arg_pos -= (arg_count + 2);
frames_on_stack--;
ptr = ptr->prev_execute_data;
if (arg_stack_consistent) {
/* skip args from incomplete frames */
while (((cur_arg_pos-1) > EG(argument_stack).elements) && *(cur_arg_pos-1)) {
cur_arg_pos--;
}
}
}
array_init(return_value);