Skip to content

Commit 51d9f32

Browse files
committed
Fixed bug #78531 (Crash when using undefined variable as object
1 parent 5a61619 commit 51d9f32

File tree

5 files changed

+62
-50
lines changed

5 files changed

+62
-50
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.4.0RC2
44

5+
- Core:
6+
. Fixed bug #78531 (Crash when using undefined variable as object). (Dmitry)
7+
58
- FFI:
69
. Added missing FFI::isNull(). (Philip Hofstetter)
710
. Fixed bug #78488 (OOB in ZEND_FUNCTION(ffi_trampoline)). (Dmitry)

Zend/tests/bug78531.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #78531 (Crash when using undefined variable as object)
3+
--FILE--
4+
<?php
5+
@$u1->a += 5;
6+
var_dump($u1->a);
7+
@$x = ++$u2->a;
8+
var_dump($u2->a);
9+
@$x = $u3->a++;
10+
var_dump($u3->a);
11+
@$u4->a->a += 5;
12+
var_dump($u4->a->a);
13+
?>
14+
--EXPECT--
15+
int(5)
16+
int(1)
17+
int(1)
18+
int(5)

Zend/zend_execute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2760,7 +2760,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
27602760
if (container_op_type == IS_CV
27612761
&& type != BP_VAR_W
27622762
&& UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
2763-
container = ZVAL_UNDEFINED_OP1();
2763+
ZVAL_UNDEFINED_OP1();
27642764
}
27652765

27662766
/* this should modify object only if it's empty */

Zend/zend_vm_def.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ ZEND_VM_HANDLER(28, ZEND_ASSIGN_OBJ_OP, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV, OP)
10881088
}
10891089
if (OP1_TYPE == IS_CV
10901090
&& UNEXPECTED(Z_TYPE_P(object) == IS_UNDEF)) {
1091-
object = ZVAL_UNDEFINED_OP1();
1091+
ZVAL_UNDEFINED_OP1();
10921092
}
10931093
object = make_real_object(object, property OPLINE_CC EXECUTE_DATA_CC);
10941094
if (UNEXPECTED(!object)) {
@@ -1263,7 +1263,6 @@ ZEND_VM_C_LABEL(assign_dim_op_new_array):
12631263
zend_binary_assign_op_obj_dim(container, dim OPLINE_CC EXECUTE_DATA_CC);
12641264
} else if (EXPECTED(Z_TYPE_P(container) <= IS_FALSE)) {
12651265
if (OP1_TYPE == IS_CV && UNEXPECTED(Z_TYPE_INFO_P(container) == IS_UNDEF)) {
1266-
ZVAL_NULL(container);
12671266
ZVAL_UNDEFINED_OP1();
12681267
}
12691268
ZVAL_ARR(container, zend_new_array(8));
@@ -1347,7 +1346,7 @@ ZEND_VM_HANDLER(132, ZEND_PRE_INC_OBJ, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV, CACH
13471346
}
13481347
if (OP1_TYPE == IS_CV
13491348
&& UNEXPECTED(Z_TYPE_P(object) == IS_UNDEF)) {
1350-
object = ZVAL_UNDEFINED_OP1();
1349+
ZVAL_UNDEFINED_OP1();
13511350
}
13521351
object = make_real_object(object, property OPLINE_CC EXECUTE_DATA_CC);
13531352
if (UNEXPECTED(!object)) {
@@ -1413,7 +1412,7 @@ ZEND_VM_HANDLER(134, ZEND_POST_INC_OBJ, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV, CAC
14131412
}
14141413
if (OP1_TYPE == IS_CV
14151414
&& UNEXPECTED(Z_TYPE_P(object) == IS_UNDEF)) {
1416-
object = ZVAL_UNDEFINED_OP1();
1415+
ZVAL_UNDEFINED_OP1();
14171416
}
14181417
object = make_real_object(object, property OPLINE_CC EXECUTE_DATA_CC);
14191418
if (UNEXPECTED(!object)) {
@@ -6249,7 +6248,7 @@ ZEND_VM_HANDLER(76, ZEND_UNSET_OBJ, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV, CACHE_S
62496248
if (Z_TYPE_P(container) != IS_OBJECT) {
62506249
if (OP1_TYPE == IS_CV
62516250
&& UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
6252-
container = ZVAL_UNDEFINED_OP1();
6251+
ZVAL_UNDEFINED_OP1();
62536252
}
62546253
break;
62556254
}

0 commit comments

Comments
 (0)