summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--Zend/tests/bug70547.phpt48
-rw-r--r--Zend/zend_builtin_functions.c16
3 files changed, 62 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 3d8abc9d9a..dec9a664e8 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ PHP NEWS
01 Oct 2015, PHP 7.0.0 RC 4
- Core:
+ . Fixed bug #70547 (unsetting function variables corrupts backtrace).
+ (Laruence)
. Fixed bug #70528 (assert() with instanceof adds apostrophes around class
name). (Laruence)
. Fixed bug #70481 (Memory leak in auto_global_copy_ctor() in ZTS build).
diff --git a/Zend/tests/bug70547.phpt b/Zend/tests/bug70547.phpt
new file mode 100644
index 0000000000..195495dcdc
--- /dev/null
+++ b/Zend/tests/bug70547.phpt
@@ -0,0 +1,48 @@
+--TEST--
+Bug #70547 (unsetting function variables corrupts backtrace)
+--FILE--
+<?php
+function brokenTrace($arg1, $arg2, $arg3){
+ backtraceWrapper();
+ unset($arg3);
+ backtraceWrapper();
+ unset($arg1);
+ backtraceWrapper();
+ unset($arg2);
+ backtraceWrapper();
+}
+brokenTrace("1st", "2nd", "3th", "4th");
+function backtraceWrapper(){
+ $bt = debug_backtrace();
+ var_dump($bt[1]['args']);
+}
+?>
+--EXPECT--
+array(4) {
+ [0]=>
+ string(3) "1st"
+ [1]=>
+ string(3) "2nd"
+ [2]=>
+ string(3) "3th"
+ [3]=>
+ string(3) "4th"
+}
+array(3) {
+ [0]=>
+ string(3) "1st"
+ [1]=>
+ string(3) "2nd"
+ [2]=>
+ string(3) "4th"
+}
+array(2) {
+ [0]=>
+ string(3) "2nd"
+ [1]=>
+ string(3) "4th"
+}
+array(1) {
+ [0]=>
+ string(3) "4th"
+}
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index e3f087b356..b0e4f6ab02 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -2233,8 +2233,12 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
if (ZEND_CALL_NUM_ARGS(call) > first_extra_arg) {
while (i < first_extra_arg) {
- if (Z_OPT_REFCOUNTED_P(p)) Z_ADDREF_P(p);
- ZEND_HASH_FILL_ADD(p);
+ if (Z_TYPE_INFO_P(p) != IS_UNDEF) {
+ if (Z_OPT_REFCOUNTED_P(p)) {
+ Z_ADDREF_P(p);
+ }
+ ZEND_HASH_FILL_ADD(p);
+ }
p++;
i++;
}
@@ -2243,8 +2247,12 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
}
while (i < num_args) {
- if (Z_OPT_REFCOUNTED_P(p)) Z_ADDREF_P(p);
- ZEND_HASH_FILL_ADD(p);
+ if (Z_TYPE_INFO_P(p) != IS_UNDEF) {
+ if (Z_OPT_REFCOUNTED_P(p)) {
+ Z_ADDREF_P(p);
+ }
+ ZEND_HASH_FILL_ADD(p);
+ }
p++;
i++;
}