]> granicus.if.org Git - php/commit
Fix lexing of nested heredoc strings in token_get_all()
authorNikita Popov <nikic@php.net>
Fri, 30 Mar 2012 18:41:44 +0000 (20:41 +0200)
committerNikita Popov <nikic@php.net>
Sat, 31 Mar 2012 19:53:30 +0000 (21:53 +0200)
commit4cf90e06c9834a52195384da760503ea055c726d
tree87a30ce3bf8e76ea04e43cd4d1b871c96214cd6e
parent15a98ece9fc43578fe1825d3c5ccafa665f63b48
Fix lexing of nested heredoc strings in token_get_all()

This fixes bug #60097.

Before two global variables CG(heredoc) and CG(heredoc_len) were used to
track the current heredoc label. In order to support nested heredoc
strings the *previous* heredoc label was assigned as the token value of
T_START_HEREDOC and the language_parser.y assigned that to CG(heredoc).

This created a dependency of the lexer on the parser. Thus the
token_get_all() function, which accesses the lexer directly without
also running the parser, was not able to tokenize nested heredoc strings
(and leaked memory). Same applies for the source-code highlighting
functions.

The new approach is to maintain a heredoc_label_stack in the lexer, which
contains all active heredoc labels.

As it is no longer required, T_START_HEREDOC and T_END_HEREDOC now don't
carry a token value anymore.

In order to make the work with zend_ptr_stack in this context more
convenient I added a new function zend_ptr_stack_top(), which retrieves the
top element of the stack (similar to zend_stack_top()).
12 files changed:
NEWS
Zend/zend_compile.c
Zend/zend_globals.h
Zend/zend_highlight.c
Zend/zend_language_parser.y
Zend/zend_language_scanner.c
Zend/zend_language_scanner.h
Zend/zend_language_scanner.l
Zend/zend_language_scanner_defs.h
Zend/zend_ptr_stack.h
ext/tokenizer/tests/bug60097.phpt [new file with mode: 0644]
ext/tokenizer/tokenizer.c