Skip to content

Commit 25de928

Browse files
committed
Fixed bug #70912 (Null ptr dereference instantiating class with invalid array property)
1 parent a03786f commit 25de928

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ PHP NEWS
33
?? ??? 2015, PHP 7.0.1
44

55
- Core:
6+
. Fixed bug #70912 (Null ptr dereference instantiating class with invalid
7+
array property). (Laruence)
68
. Fixed bug #70898, #70895 (null ptr deref and segfault with crafted callable).
79
(Anatol, Laruence)
810

Zend/tests/bug70912.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #70912 (Null ptr dereference when class property is initialised to a dereferenced value)
3+
--FILE--
4+
<?php
5+
class A {
6+
public $a=[][];
7+
}
8+
?>
9+
--EXPECTF--
10+
Fatal error: Cannot use [] for reading in %sbug70912.php on line %d

Zend/zend_compile.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7381,12 +7381,15 @@ void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
73817381
case ZEND_AST_DIM:
73827382
{
73837383
/* constant expression should be always read context ... */
7384-
73857384
zval *container, *dim;
73867385

7386+
if (ast->child[1] == NULL) {
7387+
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for reading");
7388+
}
7389+
73877390
zend_eval_const_expr(&ast->child[0]);
73887391
zend_eval_const_expr(&ast->child[1]);
7389-
if (!ast->child[0] || !ast->child[1] || ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
7392+
if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
73907393
return;
73917394
}
73927395

0 commit comments

Comments
 (0)