Skip to content

Commit 62e843f

Browse files
committed
Fix FETCH_OBJ_UNSET IS_UNDEF result
UNSET_OBJ et al. do not expect to find IS_UNDEF results for IS_INDIRECT vars. To solve this, return IS_NULL from FETCH_OBJ_UNSET when properties are uninitialized. Do the same for FETCH_OBJ_IS, as we're otherwise copying IS_UNDEF into the VAR result, which is not a valid value for VAR. Fixes OSS-Fuzz #429429090
1 parent 6f1501a commit 62e843f

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

Zend/tests/oss_fuzz_429429090.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
OSS-Fuzz #429429090
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public D $x;
8+
static D $y;
9+
}
10+
11+
$c = new C();
12+
isset($c->x[0]->prop);
13+
unset($c->x[0]->prop);
14+
isset(C::$y[0]->prop);
15+
unset(C::$y[0]->prop);
16+
17+
?>
18+
===DONE===
19+
--EXPECT--
20+
===DONE===

Zend/zend_execute.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,6 +3533,9 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
35333533
} else if (UNEXPECTED(Z_ISERROR_P(ptr))) {
35343534
ZVAL_ERROR(result);
35353535
goto end;
3536+
} else if (type == BP_VAR_UNSET && UNEXPECTED(Z_TYPE_P(ptr) == IS_UNDEF)) {
3537+
ZVAL_NULL(result);
3538+
goto end;
35363539
}
35373540

35383541
ZVAL_INDIRECT(result, ptr);
@@ -3684,6 +3687,11 @@ static zend_never_inline zval* zend_fetch_static_property_address_ex(zend_proper
36843687
return NULL;
36853688
}
36863689

3690+
if (UNEXPECTED(Z_TYPE_P(result) == IS_UNDEF)
3691+
&& (fetch_type == BP_VAR_IS || fetch_type == BP_VAR_UNSET)) {
3692+
return NULL;
3693+
}
3694+
36873695
*prop_info = property_info;
36883696

36893697
if (EXPECTED(op1_type == IS_CONST)

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ ZEND_VM_INLINE_HELPER(zend_fetch_static_prop_helper, ANY, ANY, int type)
18661866
&prop_info, opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS, type,
18671867
type == BP_VAR_W ? opline->extended_value : 0 OPLINE_CC EXECUTE_DATA_CC);
18681868
if (UNEXPECTED(!prop)) {
1869-
ZEND_ASSERT(EG(exception) || (type == BP_VAR_IS));
1869+
ZEND_ASSERT(EG(exception) || (type == BP_VAR_IS) || (type == BP_VAR_UNSET));
18701870
prop = &EG(uninitialized_zval);
18711871
} else if (UNEXPECTED(prop_info->flags & ZEND_ACC_PPP_SET_MASK)
18721872
&& (type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET)

Zend/zend_vm_execute.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)