Skip to content

Commit

Permalink
Fixed bug #80173
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Jul 2, 2021
1 parent 36f5d71 commit bdc60fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ PHP NEWS
the process). (Calvin Buckley)
. Fixed bug #73630 (Built-in Weberver - overwrite $_SERVER['request_uri']).
(cmb)
. Fixed bug #80173 (Using return value of zend_assign_to_variable() is not
safe). (Nikita)

- Intl:
. Fixed bug #72809 (Locale::lookup() wrong result with canonicalize option).
Expand Down
12 changes: 12 additions & 0 deletions Zend/tests/write_property_ref_overwrite_return.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Using return of property assignment to reference that destroys object
--FILE--
<?php

$a = new stdClass;
$a->a =& $a;
var_dump($a->a = 0);

?>
--EXPECT--
int(0)
3 changes: 2 additions & 1 deletion Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@ ZEND_API zval *zend_std_write_property(zval *object, zval *member, zval *value,
}

found:
zend_assign_to_variable(variable_ptr, value, IS_TMP_VAR, property_uses_strict_types());
variable_ptr = zend_assign_to_variable(
variable_ptr, value, IS_TMP_VAR, property_uses_strict_types());
goto exit;
}
if (Z_PROP_FLAG_P(variable_ptr) == IS_PROP_UNINIT) {
Expand Down

0 comments on commit bdc60fa

Please sign in to comment.