Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ PHP NEWS
for grouping. (Klaas Skelte van der Werf)
. Fixed bug GH-24265 (Unwind/GracefulExit discarded in
zend_fiber_execute()). (David Carlier)
. Fixed bug GH-24708 (Assertion failure in binary operators when an error
handler unsets an operand). (lazerg)

- Date:
. Fixed bug GH-20503 (Assertion failure with ext/date DateInterval property
Expand Down
54 changes: 54 additions & 0 deletions Zend/tests/gh24708.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
--TEST--
GH-24708: Assertion failure in binary operators when an error handler unsets an operand
--FILE--
<?php
set_error_handler(function ($errno, $errstr) {
echo $errstr, "\n";
unset($GLOBALS['x']);
});

$x = 1; var_dump($x + $y);
$x = 1; var_dump($x - $y);
$x = 1; var_dump($x * $y);
$x = 1; var_dump($x ** $y);
$x = 1; var_dump($x & $y);
$x = 1; var_dump($x | $y);
$x = 1; var_dump($x ^ $y);
$x = 1; var_dump($x << $y);
$x = 1; var_dump($x >> $y);
$x = 1;
try {
var_dump($x / $y);
} catch (DivisionByZeroError $e) {
echo $e->getMessage(), "\n";
}
$x = 1;
try {
var_dump($x % $y);
} catch (DivisionByZeroError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Undefined variable $y
int(0)
Undefined variable $y
int(0)
Undefined variable $y
int(0)
Undefined variable $y
int(1)
Undefined variable $y
int(0)
Undefined variable $y
int(0)
Undefined variable $y
int(0)
Undefined variable $y
int(0)
Undefined variable $y
int(0)
Undefined variable $y
Division by zero
Undefined variable $y
Modulo by zero
33 changes: 33 additions & 0 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ ZEND_VM_HELPER(zend_add_helper, ANY, ANY, zval *op_1, zval *op_2)
}
if (UNEXPECTED(Z_TYPE_INFO_P(op_2) == IS_UNDEF)) {
op_2 = ZVAL_UNDEFINED_OP2();
if (UNEXPECTED(Z_TYPE_INFO_P(op_1) == IS_UNDEF)) {
op_1 = &EG(uninitialized_zval);
}
}
add_function(EX_VAR(opline->result.var), op_1, op_2);
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
Expand Down Expand Up @@ -92,6 +95,9 @@ ZEND_VM_HELPER(zend_sub_helper, ANY, ANY, zval *op_1, zval *op_2)
}
if (UNEXPECTED(Z_TYPE_INFO_P(op_2) == IS_UNDEF)) {
op_2 = ZVAL_UNDEFINED_OP2();
if (UNEXPECTED(Z_TYPE_INFO_P(op_1) == IS_UNDEF)) {
op_1 = &EG(uninitialized_zval);
}
}
sub_function(EX_VAR(opline->result.var), op_1, op_2);
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
Expand Down Expand Up @@ -151,6 +157,9 @@ ZEND_VM_HELPER(zend_mul_helper, ANY, ANY, zval *op_1, zval *op_2)
}
if (UNEXPECTED(Z_TYPE_INFO_P(op_2) == IS_UNDEF)) {
op_2 = ZVAL_UNDEFINED_OP2();
if (UNEXPECTED(Z_TYPE_INFO_P(op_1) == IS_UNDEF)) {
op_1 = &EG(uninitialized_zval);
}
}
mul_function(EX_VAR(opline->result.var), op_1, op_2);
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
Expand Down Expand Up @@ -211,6 +220,9 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(4, ZEND_DIV, CONST|TMPVAR|CV, CONST|TMPVAR|CV)
SAVE_OPLINE();
op1 = GET_OP1_ZVAL_PTR(BP_VAR_R);
op2 = GET_OP2_ZVAL_PTR(BP_VAR_R);
if (OP1_TYPE == IS_CV && UNEXPECTED(Z_TYPE_P(op1) == IS_UNDEF)) {
op1 = &EG(uninitialized_zval);
}
div_function(EX_VAR(opline->result.var), op1, op2);
FREE_OP1();
FREE_OP2();
Expand All @@ -237,6 +249,9 @@ ZEND_VM_HELPER(zend_mod_helper, ANY, ANY, zval *op_1, zval *op_2)
}
if (UNEXPECTED(Z_TYPE_INFO_P(op_2) == IS_UNDEF)) {
op_2 = ZVAL_UNDEFINED_OP2();
if (UNEXPECTED(Z_TYPE_INFO_P(op_1) == IS_UNDEF)) {
op_1 = &EG(uninitialized_zval);
}
}
mod_function(EX_VAR(opline->result.var), op_1, op_2);
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
Expand Down Expand Up @@ -285,6 +300,9 @@ ZEND_VM_HELPER(zend_shift_left_helper, ANY, ANY, zval *op_1, zval *op_2)
}
if (UNEXPECTED(Z_TYPE_INFO_P(op_2) == IS_UNDEF)) {
op_2 = ZVAL_UNDEFINED_OP2();
if (UNEXPECTED(Z_TYPE_INFO_P(op_1) == IS_UNDEF)) {
op_1 = &EG(uninitialized_zval);
}
}
shift_left_function(EX_VAR(opline->result.var), op_1, op_2);
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
Expand Down Expand Up @@ -327,6 +345,9 @@ ZEND_VM_HELPER(zend_shift_right_helper, ANY, ANY, zval *op_1, zval *op_2)
}
if (UNEXPECTED(Z_TYPE_INFO_P(op_2) == IS_UNDEF)) {
op_2 = ZVAL_UNDEFINED_OP2();
if (UNEXPECTED(Z_TYPE_INFO_P(op_1) == IS_UNDEF)) {
op_1 = &EG(uninitialized_zval);
}
}
shift_right_function(EX_VAR(opline->result.var), op_1, op_2);
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
Expand Down Expand Up @@ -365,6 +386,9 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(12, ZEND_POW, CONST|TMPVAR|CV, CONST|TMPVAR|CV)
SAVE_OPLINE();
op1 = GET_OP1_ZVAL_PTR(BP_VAR_R);
op2 = GET_OP2_ZVAL_PTR(BP_VAR_R);
if (OP1_TYPE == IS_CV && UNEXPECTED(Z_TYPE_P(op1) == IS_UNDEF)) {
op1 = &EG(uninitialized_zval);
}
pow_function(EX_VAR(opline->result.var), op1, op2);
FREE_OP1();
FREE_OP2();
Expand Down Expand Up @@ -810,6 +834,9 @@ ZEND_VM_HELPER(zend_bw_or_helper, ANY, ANY, zval *op_1, zval *op_2)
}
if (UNEXPECTED(Z_TYPE_INFO_P(op_2) == IS_UNDEF)) {
op_2 = ZVAL_UNDEFINED_OP2();
if (UNEXPECTED(Z_TYPE_INFO_P(op_1) == IS_UNDEF)) {
op_1 = &EG(uninitialized_zval);
}
}
bitwise_or_function(EX_VAR(opline->result.var), op_1, op_2);
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
Expand Down Expand Up @@ -849,6 +876,9 @@ ZEND_VM_HELPER(zend_bw_and_helper, ANY, ANY, zval *op_1, zval *op_2)
}
if (UNEXPECTED(Z_TYPE_INFO_P(op_2) == IS_UNDEF)) {
op_2 = ZVAL_UNDEFINED_OP2();
if (UNEXPECTED(Z_TYPE_INFO_P(op_1) == IS_UNDEF)) {
op_1 = &EG(uninitialized_zval);
}
}
bitwise_and_function(EX_VAR(opline->result.var), op_1, op_2);
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
Expand Down Expand Up @@ -888,6 +918,9 @@ ZEND_VM_HELPER(zend_bw_xor_helper, ANY, ANY, zval *op_1, zval *op_2)
}
if (UNEXPECTED(Z_TYPE_INFO_P(op_2) == IS_UNDEF)) {
op_2 = ZVAL_UNDEFINED_OP2();
if (UNEXPECTED(Z_TYPE_INFO_P(op_1) == IS_UNDEF)) {
op_1 = &EG(uninitialized_zval);
}
}
bitwise_xor_function(EX_VAR(opline->result.var), op_1, op_2);
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
Expand Down
Loading
Loading