Skip to content

Commit a5d3620

Browse files
committed
Fix segfault with __COMPILER_HALT_OFFSET__ and trailing {}
Fixes OSS-Fuzz #17895.
1 parent 3124129 commit a5d3620

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Zend/tests/halt_compiler5.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Using __COMPILER_HALF_OFFSET__ with trailing {} (OSS-Fuzz #17895)
3+
--FILE--
4+
<?php
5+
__COMPILER_HALT_OFFSET__;
6+
{}
7+
--EXPECTF--
8+
Warning: Use of undefined constant __COMPILER_HALT_OFFSET__ - assumed '__COMPILER_HALT_OFFSET__' (this will throw an Error in a future version of PHP) in %s on line %d

Zend/zend_compile.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7676,6 +7676,9 @@ void zend_compile_const(znode *result, zend_ast *ast) /* {{{ */
76767676

76777677
while (last && last->kind == ZEND_AST_STMT_LIST) {
76787678
zend_ast_list *list = zend_ast_get_list(last);
7679+
if (list->children == 0) {
7680+
break;
7681+
}
76797682
last = list->child[list->children-1];
76807683
}
76817684
if (last && last->kind == ZEND_AST_HALT_COMPILER) {

0 commit comments

Comments
 (0)