com php-src: Fix ZEND_NEW live ranges: Zend/tests/bug 68652.phpt Zend/tests/temporary_cleaning_0 12.phpt Zend/zend_compile.c
| From: | Nikita Popov | Date: | Sat, 13 Feb 2016 18:04:54 +0000 |
| Subject: | com php-src: Fix ZEND_NEW live ranges: Zend/tests/bug 68652.phpt Zend/tests/temporary_cleaning_0 12.phpt Zend/zend_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-91008@lists.php.net to get a copy of this message | ||
Commit: 502dd99a6ce5c70b6b75884a338610ea0cb4e452
Author: Nikita Popov <nikic@php.net> Sat, 13 Feb 2016 18:54:49 +0100
Parents: 302214f7ce743b037659f43114222096b281c2e3
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=502dd99a6ce5c70b6b75884a338610ea0cb4e452
Log:
Fix ZEND_NEW live ranges
While the def starts at DO_FCALL, the variable should still be the
result of NEW, not DO_FCALL.
I had to fix the test for #68652, because the code started to
(correctly) free the "new self()" object, which triggered an
infinite destructor loop.
Bugs:
https://bugs.php.net/68652
Changed paths:
M Zend/tests/bug68652.phpt
A Zend/tests/temporary_cleaning_012.phpt
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/bug68652.phpt b/Zend/tests/bug68652.phpt
index e86312b..8e54af2 100644
--- a/Zend/tests/bug68652.phpt
+++ b/Zend/tests/bug68652.phpt
@@ -28,6 +28,7 @@ class Bar {
}
public function __destruct() {
+ if (!isset(self::$instance)) return;
Foo::getInstance();
}
}
diff --git a/Zend/tests/temporary_cleaning_012.phpt b/Zend/tests/temporary_cleaning_012.phpt
new file mode 100644
index 0000000..fdbea6d
--- /dev/null
+++ b/Zend/tests/temporary_cleaning_012.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Live range of ZEND_NEW must be assigned to correct variable
+--FILE--
+<?php
+
+class Foo {
+ public static function test() {
+ self::$property = new self;
+ }
+}
+
+try {
+ Foo::test();
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Access to undeclared static property: Foo::$property
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 83d042d..e318309 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -1960,6 +1960,7 @@ static void zend_find_live_range(zend_op *opline, zend_uchar type, uint32_t
var)
while (def != CG(active_op_array)->opcodes) {
def--;
if (def->result_type == type && def->result.var == var) {
+ uint32_t var;
if (def->opcode == ZEND_ADD_ARRAY_ELEMENT ||
def->opcode == ZEND_ROPE_ADD) {
/* not a real definition */
@@ -1980,7 +1981,10 @@ static void zend_find_live_range(zend_op *opline, zend_uchar type, uint32_t
var)
} else if (def->opcode == ZEND_FAST_CALL) {
/* fast_calls don't have to be destroyed */
break;
- } else if (def->opcode == ZEND_NEW) {
+ }
+
+ var = def->result.var;
+ if (def->opcode == ZEND_NEW) {
/* Objects created via ZEND_NEW are only fully initialized
* after the DO_FCALL (constructor call) */
def = CG(active_op_array)->opcodes + def->op2.opline_num - 1;
@@ -1988,11 +1992,12 @@ static void zend_find_live_range(zend_op *opline, zend_uchar type, uint32_t
var)
break;
}
}
+
zend_end_live_range(CG(active_op_array),
zend_start_live_range_ex(CG(active_op_array),
def + 1 - CG(active_op_array)->opcodes),
opline - CG(active_op_array)->opcodes,
- ZEND_LIVE_TMPVAR, def->result.var);
+ ZEND_LIVE_TMPVAR, var);
break;
}
}