summaryrefslogtreecommitdiff
path: root/Zend/zend_language_scanner.l
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/zend_language_scanner.l')
-rw-r--r--Zend/zend_language_scanner.l143
1 files changed, 66 insertions, 77 deletions
diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l
index 8c5a4e47f5..fbe9ef775f 100644
--- a/Zend/zend_language_scanner.l
+++ b/Zend/zend_language_scanner.l
@@ -116,7 +116,7 @@ do { \
#define SET_DOUBLE_QUOTES_SCANNED_LENGTH(len) SCNG(scanned_string_len) = (len)
#define GET_DOUBLE_QUOTES_SCANNED_LENGTH() SCNG(scanned_string_len)
-#define IS_LABEL_START(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z') || (c) == '_' || (c) >= 0x7F)
+#define IS_LABEL_START(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z') || (c) == '_' || (c) >= 0x80)
#define ZEND_IS_OCT(c) ((c)>='0' && (c)<='7')
#define ZEND_IS_HEX(c) (((c)>='0' && (c)<='9') || ((c)>='a' && (c)<='f') || ((c)>='A' && (c)<='F'))
@@ -178,6 +178,7 @@ void startup_scanner(void)
{
CG(parse_error) = 0;
CG(doc_comment) = NULL;
+ CG(extra_fn_flags) = 0;
zend_stack_init(&SCNG(state_stack), sizeof(int));
zend_ptr_stack_init(&SCNG(heredoc_label_stack));
}
@@ -225,6 +226,7 @@ ZEND_API void zend_save_lexical_state(zend_lex_state *lex_state)
lex_state->script_encoding = SCNG(script_encoding);
lex_state->on_event = SCNG(on_event);
+ lex_state->on_event_context = SCNG(on_event_context);
lex_state->ast = CG(ast);
lex_state->ast_arena = CG(ast_arena);
@@ -264,6 +266,7 @@ ZEND_API void zend_restore_lexical_state(zend_lex_state *lex_state)
SCNG(script_encoding) = lex_state->script_encoding;
SCNG(on_event) = lex_state->on_event;
+ SCNG(on_event_context) = lex_state->on_event_context;
CG(ast) = lex_state->ast;
CG(ast_arena) = lex_state->ast_arena;
@@ -283,7 +286,9 @@ ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle)
ZEND_API void zend_lex_tstring(zval *zv)
{
- if (SCNG(on_event)) SCNG(on_event)(ON_FEEDBACK, T_STRING, 0);
+ if (SCNG(on_event)) {
+ SCNG(on_event)(ON_FEEDBACK, T_STRING, 0, SCNG(on_event_context));
+ }
ZVAL_STRINGL(zv, (char*)SCNG(yy_text), SCNG(yy_leng));
}
@@ -383,7 +388,7 @@ static const zend_encoding* zend_multibyte_detect_unicode(void)
/* check if the NULL byte is after the __HALT_COMPILER(); */
pos2 = LANG_SCNG(script_org);
- while (pos1 - pos2 >= sizeof("__HALT_COMPILER();")-1) {
+ while ((size_t)(pos1 - pos2) >= sizeof("__HALT_COMPILER();")-1) {
pos2 = memchr(pos2, '_', pos1 - pos2);
if (!pos2) break;
pos2++;
@@ -500,7 +505,7 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle)
/* The shebang line was read, get the current position to obtain the buffer start */
if (CG(start_lineno) == 2 && file_handle->type == ZEND_HANDLE_FP && file_handle->handle.fp) {
- if ((offset = ftell(file_handle->handle.fp)) == -1) {
+ if ((offset = ftell(file_handle->handle.fp)) == (size_t)-1) {
offset = 0;
}
}
@@ -521,7 +526,7 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle)
SCNG(yy_in) = file_handle;
SCNG(yy_start) = NULL;
- if (size != -1) {
+ if (size != (size_t)-1) {
if (CG(multibyte)) {
SCNG(script_org) = (unsigned char*)buf;
SCNG(script_org_size) = size;
@@ -568,6 +573,48 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle)
}
END_EXTERN_C()
+static zend_op_array *zend_compile(int type)
+{
+ zend_op_array *op_array = NULL;
+ zend_bool original_in_compilation = CG(in_compilation);
+
+ CG(in_compilation) = 1;
+ CG(ast) = NULL;
+ CG(ast_arena) = zend_arena_create(1024 * 32);
+
+ if (!zendparse()) {
+ zend_file_context original_file_context;
+ zend_oparray_context original_oparray_context;
+ zend_op_array *original_active_op_array = CG(active_op_array);
+
+ op_array = emalloc(sizeof(zend_op_array));
+ init_op_array(op_array, type, INITIAL_OP_ARRAY_SIZE);
+ CG(active_op_array) = op_array;
+
+ if (zend_ast_process) {
+ zend_ast_process(CG(ast));
+ }
+
+ zend_file_context_begin(&original_file_context);
+ zend_oparray_context_begin(&original_oparray_context);
+ zend_compile_top_stmt(CG(ast));
+ zend_emit_final_return(type == ZEND_USER_FUNCTION);
+ op_array->line_start = 1;
+ op_array->line_end = CG(zend_lineno);
+ pass_two(op_array);
+ zend_oparray_context_end(&original_oparray_context);
+ zend_file_context_end(&original_file_context);
+
+ CG(active_op_array) = original_active_op_array;
+ }
+
+ zend_ast_destroy(CG(ast));
+ zend_arena_destroy(CG(ast_arena));
+
+ CG(in_compilation) = original_in_compilation;
+
+ return op_array;
+}
ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type)
{
@@ -583,41 +630,7 @@ ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type)
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename);
}
} else {
- zend_bool original_in_compilation = CG(in_compilation);
- CG(in_compilation) = 1;
-
- CG(ast) = NULL;
- CG(ast_arena) = zend_arena_create(1024 * 32);
- if (!zendparse()) {
- zval retval_zv;
- zend_file_context original_file_context;
- zend_oparray_context original_oparray_context;
- zend_op_array *original_active_op_array = CG(active_op_array);
- op_array = emalloc(sizeof(zend_op_array));
- init_op_array(op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE);
- CG(active_op_array) = op_array;
- ZVAL_LONG(&retval_zv, 1);
-
- if (zend_ast_process) {
- zend_ast_process(CG(ast));
- }
-
- zend_file_context_begin(&original_file_context);
- zend_oparray_context_begin(&original_oparray_context);
- zend_compile_top_stmt(CG(ast));
- zend_emit_final_return(&retval_zv);
- op_array->line_start = 1;
- op_array->line_end = CG(zend_lineno);
- pass_two(op_array);
- zend_oparray_context_end(&original_oparray_context);
- zend_file_context_end(&original_file_context);
-
- CG(active_op_array) = original_active_op_array;
- }
-
- zend_ast_destroy(CG(ast));
- zend_arena_destroy(CG(ast_arena));
- CG(in_compilation) = original_in_compilation;
+ op_array = zend_compile(ZEND_USER_FUNCTION);
}
zend_restore_lexical_state(&original_lex_state);
@@ -732,13 +745,11 @@ ZEND_API size_t zend_get_scanned_file_offset(void)
return offset;
}
-
zend_op_array *compile_string(zval *source_string, char *filename)
{
zend_lex_state original_lex_state;
zend_op_array *op_array = NULL;
zval tmp;
- zend_bool original_in_compilation = CG(in_compilation);
if (Z_STRLEN_P(source_string)==0) {
return NULL;
@@ -748,45 +759,15 @@ zend_op_array *compile_string(zval *source_string, char *filename)
convert_to_string(&tmp);
source_string = &tmp;
- CG(in_compilation) = 1;
zend_save_lexical_state(&original_lex_state);
if (zend_prepare_string_for_scanning(source_string, filename) == SUCCESS) {
- CG(ast) = NULL;
- CG(ast_arena) = zend_arena_create(1024 * 32);
BEGIN(ST_IN_SCRIPTING);
-
- if (!zendparse()) {
- zend_file_context original_file_context;
- zend_oparray_context original_oparray_context;
- zend_op_array *original_active_op_array = CG(active_op_array);
- op_array = emalloc(sizeof(zend_op_array));
- init_op_array(op_array, ZEND_EVAL_CODE, INITIAL_OP_ARRAY_SIZE);
- CG(active_op_array) = op_array;
-
- if (zend_ast_process) {
- zend_ast_process(CG(ast));
- }
-
- zend_file_context_begin(&original_file_context);
- zend_oparray_context_begin(&original_oparray_context);
- zend_compile_top_stmt(CG(ast));
- zend_emit_final_return(NULL);
- op_array->line_start = 1;
- op_array->line_end = CG(zend_lineno);
- pass_two(op_array);
- zend_oparray_context_end(&original_oparray_context);
- zend_file_context_end(&original_file_context);
-
- CG(active_op_array) = original_active_op_array;
- }
-
- zend_ast_destroy(CG(ast));
- zend_arena_destroy(CG(ast_arena));
+ op_array = zend_compile(ZEND_EVAL_CODE);
}
zend_restore_lexical_state(&original_lex_state);
zval_dtor(&tmp);
- CG(in_compilation) = original_in_compilation;
+
return op_array;
}
@@ -1067,6 +1048,12 @@ static int zend_scan_escape_string(zval *zendlval, char *str, int len, char quot
Z_STRLEN_P(zendlval)--;
}
}
+ if (octal_buf[2] &&
+ (octal_buf[0] > '3')) {
+ /* 3 octit values must not overflow 0xFF (\377) */
+ zend_error(E_COMPILE_WARNING, "Octal escape sequence overflow \\%s is greater than \\377", octal_buf);
+ }
+
*t++ = (char) ZEND_STRTOL(octal_buf, NULL, 8);
} else {
*t++ = '\\';
@@ -1099,7 +1086,9 @@ static int zend_scan_escape_string(zval *zendlval, char *str, int len, char quot
static zend_always_inline int emit_token(int token, int token_line)
{
- if(SCNG(on_event)) SCNG(on_event)(ON_TOKEN, token, token_line);
+ if (SCNG(on_event)) {
+ SCNG(on_event)(ON_TOKEN, token, token_line, SCNG(on_event_context));
+ }
return token;
}
@@ -1121,7 +1110,7 @@ DNUM ([0-9]*"."[0-9]+)|([0-9]+"."[0-9]*)
EXPONENT_DNUM (({LNUM}|{DNUM})[eE][+-]?{LNUM})
HNUM "0x"[0-9a-fA-F]+
BNUM "0b"[01]+
-LABEL [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*
+LABEL [a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*
WHITESPACE [ \n\r\t]+
TABS_AND_SPACES [ \t]*
TOKENS [;:,.\[\]()|^&+-/*=%!~$<>?@]
@@ -1859,7 +1848,7 @@ inline_char_handler:
/* Make sure a label character follows "->", otherwise there is no property
* and "->" will be taken literally
*/
-<ST_DOUBLE_QUOTES,ST_HEREDOC,ST_BACKQUOTE>"$"{LABEL}"->"[a-zA-Z_\x7f-\xff] {
+<ST_DOUBLE_QUOTES,ST_HEREDOC,ST_BACKQUOTE>"$"{LABEL}"->"[a-zA-Z_\x80-\xff] {
yyless(yyleng - 3);
yy_push_state(ST_LOOKING_FOR_PROPERTY);
zend_copy_value(zendlval, (yytext+1), (yyleng-1));