summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2005-06-23 12:00:13 +0000
committerDmitry Stogov <dmitry@php.net>2005-06-23 12:00:13 +0000
commitf3f97394b2f650914933dba8701b95bef69eb62a (patch)
tree88b86dd767cf1ac564249e0e2f6e239a4d2eacc5
parent544387905386c30a1f9e801436782858c7a17bbb (diff)
downloadphp-git-f3f97394b2f650914933dba8701b95bef69eb62a.tar.gz
Fixed bug #28377 (debug_backtrace is intermittently passing args)
-rw-r--r--NEWS1
-rwxr-xr-xZend/tests/bug28377.phpt23
-rw-r--r--Zend/zend_builtin_functions.c30
3 files changed, 54 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 724ca6fa8a..05b8da9e25 100644
--- 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
index 0000000000..9d1b43472c
--- /dev/null
+++ b/Zend/tests/bug28377.phpt
@@ -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
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index ba54430bbe..37af1069b9 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -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);