Skip to content

Commit

Permalink
Fix segfault with __COMPILER_HALT_OFFSET__ and trailing {}
Browse files Browse the repository at this point in the history
Fixes OSS-Fuzz #17895.
  • Loading branch information
nikic committed Oct 2, 2019
1 parent 3124129 commit a5d3620
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Zend/tests/halt_compiler5.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--TEST--
Using __COMPILER_HALF_OFFSET__ with trailing {} (OSS-Fuzz #17895)
--FILE--
<?php
__COMPILER_HALT_OFFSET__;
{}
--EXPECTF--
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
3 changes: 3 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -7676,6 +7676,9 @@ void zend_compile_const(znode *result, zend_ast *ast) /* {{{ */

while (last && last->kind == ZEND_AST_STMT_LIST) {
zend_ast_list *list = zend_ast_get_list(last);
if (list->children == 0) {
break;
}
last = list->child[list->children-1];
}
if (last && last->kind == ZEND_AST_HALT_COMPILER) {
Expand Down

0 comments on commit a5d3620

Please sign in to comment.