Skip to content

Commit bdc60fa

Browse files
committed
Fixed bug #80173
The analysis in the bug report wasn't correct (at least not in this case -- there may still be a more general problem here), the issue was that write_property returned the original variable_ptr rather than the zend_assign_to_variable() return value, which will DEREF the variable before overwriting it.
1 parent 36f5d71 commit bdc60fa

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ PHP NEWS
1111
the process). (Calvin Buckley)
1212
. Fixed bug #73630 (Built-in Weberver - overwrite $_SERVER['request_uri']).
1313
(cmb)
14+
. Fixed bug #80173 (Using return value of zend_assign_to_variable() is not
15+
safe). (Nikita)
1416

1517
- Intl:
1618
. Fixed bug #72809 (Locale::lookup() wrong result with canonicalize option).
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Using return of property assignment to reference that destroys object
3+
--FILE--
4+
<?php
5+
6+
$a = new stdClass;
7+
$a->a =& $a;
8+
var_dump($a->a = 0);
9+
10+
?>
11+
--EXPECT--
12+
int(0)

Zend/zend_object_handlers.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,8 @@ ZEND_API zval *zend_std_write_property(zval *object, zval *member, zval *value,
849849
}
850850

851851
found:
852-
zend_assign_to_variable(variable_ptr, value, IS_TMP_VAR, property_uses_strict_types());
852+
variable_ptr = zend_assign_to_variable(
853+
variable_ptr, value, IS_TMP_VAR, property_uses_strict_types());
853854
goto exit;
854855
}
855856
if (Z_PROP_FLAG_P(variable_ptr) == IS_PROP_UNINIT) {

0 commit comments

Comments
 (0)