com php-src: Fix handling of nullsafe method in empty(): Zend/tests/nullsafe_operator/030.phpt Zend/zend_c ompile.c
| From: | Nikita Popov | Date: | Mon, 03 Aug 2020 08:16:38 +0000 |
| Subject: | com php-src: Fix handling of nullsafe method in empty(): Zend/tests/nullsafe_operator/030.phpt Zend/zend_c ompile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-112501@lists.php.net to get a copy of this message | ||
Commit: a4c015b4b272b992379517e3b0e8d5c6c6fb213d
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 3 Aug 2020 10:16:04 +0200
Parents: 05c5c9370537ff2fc8d37629beb6ae8e354500c8
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a4c015b4b272b992379517e3b0e8d5c6c6fb213d
Log:
Fix handling of nullsafe method in empty()
Fixes oss-fuzz #24627.
Bugs:
https://bugs.php.net/24627
Changed paths:
A Zend/tests/nullsafe_operator/030.phpt
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/nullsafe_operator/030.phpt b/Zend/tests/nullsafe_operator/030.phpt
new file mode 100644
index 0000000000..7bff0b2524
--- /dev/null
+++ b/Zend/tests/nullsafe_operator/030.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Empty on nullsafe method
+--FILE--
+<?php
+
+class Test {
+ public function method($value) {
+ return $value;
+ }
+}
+
+$null = null;
+var_dump(empty($null?->method()));
+$test = new Test;
+var_dump(empty($test?->method(false)));
+var_dump(empty($test?->method(42)));
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 78b72de1a7..5e61760e90 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -8684,7 +8684,6 @@ void zend_compile_isset_or_empty(znode *result, zend_ast *ast) /* {{{ */
ZEND_ASSERT(ast->kind == ZEND_AST_ISSET || ast->kind == ZEND_AST_EMPTY);
- zend_short_circuiting_mark_inner(var_ast);
if (!zend_is_variable(var_ast)) {
if (ast->kind == ZEND_AST_EMPTY) {
/* empty(expr) can be transformed to !expr */
@@ -8698,6 +8697,7 @@ void zend_compile_isset_or_empty(znode *result, zend_ast *ast) /* {{{ */
}
}
+ zend_short_circuiting_mark_inner(var_ast);
switch (var_ast->kind) {
case ZEND_AST_VAR:
if (is_this_fetch(var_ast)) {