Skip to content

Commit f92a036

Browse files
committed
Check for null EX(func) in write_property
This can happen if zend_call_function inserted a dummy frame, and we already switched to the dummy frame in leave_helper, and an exception is thrown during CV destruction. Fixes oss-fuzz #25343.
1 parent 3761293 commit f92a036

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
@@ -809,6 +809,13 @@ ZEND_API zval *zend_std_read_property(zval *object, zval *member, int type, void
809809
}
810810
/* }}} */
811811

812+
static zend_always_inline zend_bool property_uses_strict_types() {
813+
zend_execute_data *execute_data = EG(current_execute_data);
814+
return execute_data
815+
&& execute_data->func
816+
&& ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data));
817+
}
818+
812819
ZEND_API zval *zend_std_write_property(zval *object, zval *member, zval *value, void **cache_slot) /* {{{ */
813820
{
814821
zend_object *zobj;
@@ -833,7 +840,7 @@ ZEND_API zval *zend_std_write_property(zval *object, zval *member, zval *value,
833840

834841
if (UNEXPECTED(prop_info)) {
835842
ZVAL_COPY_VALUE(&tmp, value);
836-
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, EG(current_execute_data) && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
843+
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, property_uses_strict_types()))) {
837844
Z_TRY_DELREF_P(value);
838845
variable_ptr = &EG(error_zval);
839846
goto exit;
@@ -842,7 +849,7 @@ ZEND_API zval *zend_std_write_property(zval *object, zval *member, zval *value,
842849
}
843850

844851
found:
845-
zend_assign_to_variable(variable_ptr, value, IS_TMP_VAR, EG(current_execute_data) && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data)));
852+
zend_assign_to_variable(variable_ptr, value, IS_TMP_VAR, property_uses_strict_types());
846853
goto exit;
847854
}
848855
if (Z_PROP_FLAG_P(variable_ptr) == IS_PROP_UNINIT) {
@@ -898,7 +905,7 @@ ZEND_API zval *zend_std_write_property(zval *object, zval *member, zval *value,
898905

899906
if (UNEXPECTED(prop_info)) {
900907
ZVAL_COPY_VALUE(&tmp, value);
901-
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
908+
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, property_uses_strict_types()))) {
902909
zval_ptr_dtor(value);
903910
goto exit;
904911
}

0 commit comments

Comments
 (0)