Skip to content

Commit 88a8ebc

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Check for null EX(func) in write_property
2 parents 5c1cf76 + f92a036 commit 88a8ebc

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
EX(func) can be null during write_property in an edge case
3+
--FILE--
4+
<?php
5+
class a {
6+
public static $i = 0;
7+
function __destruct() {
8+
if (self::$i++ != 0) throw new Exception;
9+
$b = new a;
10+
echo $b;
11+
}
12+
}
13+
new a;
14+
?>
15+
--EXPECTF--
16+
Fatal error: Uncaught Error: Object of class a could not be converted to string in %s:%d
17+
Stack trace:
18+
#0 %s(%d): a->__destruct()
19+
#1 {main}
20+
21+
Next Exception in %s:%d
22+
Stack trace:
23+
#0 %s(%d): a->__destruct()
24+
#1 {main}
25+
thrown in %s on line %d

Zend/zend_object_handlers.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,13 @@ ZEND_API zval *zend_std_read_property(zend_object *zobj, zend_string *name, int
691691
}
692692
/* }}} */
693693

694+
static zend_always_inline zend_bool property_uses_strict_types() {
695+
zend_execute_data *execute_data = EG(current_execute_data);
696+
return execute_data
697+
&& execute_data->func
698+
&& ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data));
699+
}
700+
694701
ZEND_API zval *zend_std_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot) /* {{{ */
695702
{
696703
zval *variable_ptr, tmp;
@@ -707,7 +714,7 @@ ZEND_API zval *zend_std_write_property(zend_object *zobj, zend_string *name, zva
707714

708715
if (UNEXPECTED(prop_info)) {
709716
ZVAL_COPY_VALUE(&tmp, value);
710-
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, EG(current_execute_data) && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
717+
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, property_uses_strict_types()))) {
711718
Z_TRY_DELREF_P(value);
712719
variable_ptr = &EG(error_zval);
713720
goto exit;
@@ -716,7 +723,7 @@ ZEND_API zval *zend_std_write_property(zend_object *zobj, zend_string *name, zva
716723
}
717724

718725
found:
719-
zend_assign_to_variable(variable_ptr, value, IS_TMP_VAR, EG(current_execute_data) && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data)));
726+
zend_assign_to_variable(variable_ptr, value, IS_TMP_VAR, property_uses_strict_types());
720727
goto exit;
721728
}
722729
if (Z_PROP_FLAG_P(variable_ptr) == IS_PROP_UNINIT) {
@@ -772,7 +779,7 @@ ZEND_API zval *zend_std_write_property(zend_object *zobj, zend_string *name, zva
772779

773780
if (UNEXPECTED(prop_info)) {
774781
ZVAL_COPY_VALUE(&tmp, value);
775-
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
782+
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, property_uses_strict_types()))) {
776783
zval_ptr_dtor(value);
777784
goto exit;
778785
}

0 commit comments

Comments
 (0)