Skip to content

Fix lexing of nested heredoc strings in token_get_all() #31

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

Merged
merged 1 commit into from
Aug 20, 2012

Conversation

nikic
Copy link
Member

@nikic nikic commented Mar 31, 2012

This fixes bug #60097 (https://bugs.php.net/bug.php?id=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()).

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()).
@php-pulls php-pulls merged commit 4cf90e0 into php:master Aug 20, 2012
php-pulls pushed a commit that referenced this pull request Dec 20, 2013
@rentalhost
Copy link

+1

hikari-no-yume added a commit to hikari-no-yume/php-src that referenced this pull request Jan 9, 2015
hikari-no-yume added a commit to hikari-no-yume/php-src that referenced this pull request Jan 12, 2015
hikari-no-yume added a commit to hikari-no-yume/php-src that referenced this pull request Jan 15, 2015
hikari-no-yume added a commit to hikari-no-yume/php-src that referenced this pull request Jan 17, 2015
hikari-no-yume added a commit to hikari-no-yume/php-src that referenced this pull request Jan 17, 2015
hikari-no-yume added a commit to hikari-no-yume/php-src that referenced this pull request Jan 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants