Skip to content

Fixed bug #70912 (Null ptr dereference instantiating class with inval… #1637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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
10 changes: 10 additions & 0 deletions Zend/tests/bug70912.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Bug #70912 Null ptr dereference instantiating class with invalid array property
--FILE--
<?php
new class {
public $a = [][];
};
?>
--EXPECTF--
Fatal error: Cannot use [] for reading in %s on line %d
7 changes: 6 additions & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -7386,7 +7386,12 @@ void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */

zend_eval_const_expr(&ast->child[0]);
zend_eval_const_expr(&ast->child[1]);
if (!ast->child[0] || !ast->child[1] || ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {

if (!ast->child[1]) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for reading");
}

if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
return;
}

Expand Down