]> granicus.if.org Git - php/commitdiff
Fixed bug #28377 (debug_backtrace is intermittently passing args)
authorDmitry Stogov <dmitry@php.net>
Thu, 23 Jun 2005 12:00:13 +0000 (12:00 +0000)
committerDmitry Stogov <dmitry@php.net>
Thu, 23 Jun 2005 12:00:13 +0000 (12:00 +0000)
NEWS
Zend/tests/bug28377.phpt [new file with mode: 0755]
Zend/zend_builtin_functions.c

diff --git a/NEWS b/NEWS
index 724ca6fa8a3a430edca5c0f334df8297d04dfd01..05b8da9e2511bbfed31b08c97120765484aaf523 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/Zend/tests/bug28377.phpt b/Zend/tests/bug28377.phpt
new file mode 100755 (executable)
index 0000000..9d1b434
--- /dev/null
@@ -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
index ba54430bbe41ab634aa059db15921747406460b5..37af1069b9165d9b150fb2eeb4baa4e4cd37e6fd 100644 (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);