From 4cf90e06c9834a52195384da760503ea055c726d Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 30 Mar 2012 20:41:44 +0200 Subject: 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()). --- Zend/zend_ptr_stack.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Zend/zend_ptr_stack.h') diff --git a/Zend/zend_ptr_stack.h b/Zend/zend_ptr_stack.h index cc062de872..9f6fc13161 100644 --- a/Zend/zend_ptr_stack.h +++ b/Zend/zend_ptr_stack.h @@ -111,6 +111,11 @@ static zend_always_inline void *zend_ptr_stack_pop(zend_ptr_stack *stack) return *(--stack->top_element); } +static inline void *zend_ptr_stack_top(zend_ptr_stack *stack) +{ + return stack->elements[stack->top - 1]; +} + #endif /* ZEND_PTR_STACK_H */ /* -- cgit v1.2.1