From c9f6d5941e726a83d84dad77a07324744db2ca4b Mon Sep 17 00:00:00 2001 From: Jani Taskinen Date: Mon, 23 Jul 2007 16:17:10 +0000 Subject: [PATCH] MFH: - Fixed buf #42071 (ini scanner allows using NULL as option name). MFH: Use Z_* macros to access the zvals. --- Zend/zend.h | 1 + Zend/zend_ini_parser.y | 88 ++++++++++++++++++++--------------------- Zend/zend_ini_scanner.l | 52 ++++++++++++------------ Zend/zend_strtod.c | 1 + 4 files changed, 71 insertions(+), 71 deletions(-) diff --git a/Zend/zend.h b/Zend/zend.h index cfcdc1623c..ed8ba3b8e9 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -648,6 +648,7 @@ END_EXTERN_C() #define ZEND_MAX_RESERVED_RESOURCES 4 +#include "zend_operators.h" #include "zend_variables.h" #endif /* ZEND_H */ diff --git a/Zend/zend_ini_parser.y b/Zend/zend_ini_parser.y index 9346acfda7..d392c41e5a 100644 --- a/Zend/zend_ini_parser.y +++ b/Zend/zend_ini_parser.y @@ -3,7 +3,7 @@ +----------------------------------------------------------------------+ | Zend Engine | +----------------------------------------------------------------------+ - | Copyright (c) 1998-2006 Zend Technologies Ltd. (http://www.zend.com) | + | Copyright (c) 1998-2007 Zend Technologies Ltd. (http://www.zend.com) | +----------------------------------------------------------------------+ | This source file is subject to version 2.00 of the Zend license, | | that is bundled with this package in the file LICENSE, and is | @@ -58,11 +58,11 @@ void zend_ini_do_op(char type, zval *result, zval *op1, zval *op2) int i_op1, i_op2; char str_result[MAX_LENGTH_OF_LONG]; - i_op1 = atoi(op1->value.str.val); - free(op1->value.str.val); + i_op1 = atoi(Z_STRVAL_P(op1)); + free(Z_STRVAL_P(op1)); if (op2) { - i_op2 = atoi(op2->value.str.val); - free(op2->value.str.val); + i_op2 = atoi(Z_STRVAL_P(op2)); + free(Z_STRVAL_P(op2)); } else { i_op2 = 0; } @@ -85,30 +85,30 @@ void zend_ini_do_op(char type, zval *result, zval *op1, zval *op2) break; } - result->value.str.len = zend_sprintf(str_result, "%d", i_result); - result->value.str.val = (char *) malloc(result->value.str.len+1); - memcpy(result->value.str.val, str_result, result->value.str.len); - result->value.str.val[result->value.str.len] = 0; - result->type = IS_STRING; + Z_STRLEN_P(result) = zend_sprintf(str_result, "%d", i_result); + Z_STRVAL_P(result) = (char *) malloc(Z_STRLEN_P(result)+1); + memcpy(Z_STRVAL_P(result), str_result, Z_STRLEN_P(result)); + Z_STRVAL_P(result)[Z_STRLEN_P(result)] = 0; + Z_TYPE_P(result) = IS_STRING; } void zend_ini_init_string(zval *result) { - result->value.str.val = malloc(1); - result->value.str.val[0] = 0; - result->value.str.len = 0; - result->type = IS_STRING; + Z_STRVAL_P(result) = malloc(1); + Z_STRVAL_P(result)[0] = 0; + Z_STRLEN_P(result) = 0; + Z_TYPE_P(result) = IS_STRING; } void zend_ini_add_string(zval *result, zval *op1, zval *op2) -{ - int length = op1->value.str.len + op2->value.str.len; - - result->value.str.val = (char *) realloc(op1->value.str.val, length+1); - memcpy(result->value.str.val+op1->value.str.len, op2->value.str.val, op2->value.str.len); - result->value.str.val[length] = 0; - result->value.str.len = length; - result->type = IS_STRING; +{ + int length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2); + + Z_STRVAL_P(result) = (char *) realloc(Z_STRVAL_P(op1), length+1); + memcpy(Z_STRVAL_P(result)+Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2)); + Z_STRVAL_P(result)[length] = 0; + Z_STRLEN_P(result) = length; + Z_TYPE_P(result) = IS_STRING; } void zend_ini_get_constant(zval *result, zval *name) @@ -116,15 +116,15 @@ void zend_ini_get_constant(zval *result, zval *name) zval z_constant; TSRMLS_FETCH(); - if (!memchr(name->value.str.val, ':', name->value.str.len) - && zend_get_constant(name->value.str.val, name->value.str.len, &z_constant TSRMLS_CC)) { + if (!memchr(Z_STRVAL_P(name), ':', Z_STRLEN_P(name)) + && zend_get_constant(Z_STRVAL_P(name), Z_STRLEN_P(name), &z_constant TSRMLS_CC)) { /* z_constant is emalloc()'d */ convert_to_string(&z_constant); - result->value.str.val = zend_strndup(z_constant.value.str.val, z_constant.value.str.len); - result->value.str.len = z_constant.value.str.len; - result->type = z_constant.type; + Z_STRVAL_P(result) = zend_strndup(Z_STRVAL(z_constant), Z_STRLEN(z_constant)); + Z_STRLEN_P(result) = Z_STRLEN(z_constant); + Z_TYPE_P(result) = Z_TYPE(z_constant); zval_dtor(&z_constant); - free(name->value.str.val); + free(Z_STRVAL_P(name)); } else { *result = *name; } @@ -136,13 +136,13 @@ void zend_ini_get_var(zval *result, zval *name) char *envvar; TSRMLS_FETCH(); - if (zend_get_configuration_directive(name->value.str.val, name->value.str.len+1, &curval) == SUCCESS) { - result->value.str.val = zend_strndup(curval.value.str.val, curval.value.str.len); - result->value.str.len = curval.value.str.len; - } else if ((envvar = zend_getenv(name->value.str.val, name->value.str.len TSRMLS_CC)) != NULL || - (envvar = getenv(name->value.str.val)) != NULL) { - result->value.str.val = strdup(envvar); - result->value.str.len = strlen(envvar); + if (zend_get_configuration_directive(Z_STRVAL_P(name), Z_STRLEN_P(name)+1, &curval) == SUCCESS) { + Z_STRVAL_P(result) = zend_strndup(Z_STRVAL(curval), Z_STRLEN(curval)); + Z_STRLEN_P(result) = Z_STRLEN(curval); + } else if ((envvar = zend_getenv(Z_STRVAL_P(name), Z_STRLEN_P(name) TSRMLS_CC)) != NULL || + (envvar = getenv(Z_STRVAL_P(name))) != NULL) { + Z_STRVAL_P(result) = strdup(envvar); + Z_STRLEN_P(result) = strlen(envvar); } else { zend_ini_init_string(result); } @@ -252,22 +252,22 @@ statement_list: statement: TC_STRING '=' string_or_value { #if DEBUG_CFG_PARSER - printf("'%s' = '%s'\n", $1.value.str.val, $3.value.str.val); + printf("'%s' = '%s'\n", Z_STRVAL($1), Z_STRVAL($3)); #endif ZEND_INI_PARSER_CB(&$1, &$3, ZEND_INI_PARSER_ENTRY, ZEND_INI_PARSER_ARG); - free($1.value.str.val); - free($3.value.str.val); + free(Z_STRVAL($1)); + free(Z_STRVAL($3)); } | TC_STRING BRACK '=' string_or_value { #if DEBUG_CFG_PARSER - printf("'%s'[ ] = '%s'\n", $1.value.str.val, $4.value.str.val); + printf("'%s'[ ] = '%s'\n", Z_STRVAL($1), Z_STRVAL($4)); #endif ZEND_INI_PARSER_CB(&$1, &$4, ZEND_INI_PARSER_POP_ENTRY, ZEND_INI_PARSER_ARG); - free($1.value.str.val); - free($4.value.str.val); + free(Z_STRVAL($1)); + free(Z_STRVAL($4)); } - | TC_STRING { ZEND_INI_PARSER_CB(&$1, NULL, ZEND_INI_PARSER_ENTRY, ZEND_INI_PARSER_ARG); free($1.value.str.val); } - | SECTION { ZEND_INI_PARSER_CB(&$1, NULL, ZEND_INI_PARSER_SECTION, ZEND_INI_PARSER_ARG); free($1.value.str.val); } + | TC_STRING { ZEND_INI_PARSER_CB(&$1, NULL, ZEND_INI_PARSER_ENTRY, ZEND_INI_PARSER_ARG); free(Z_STRVAL($1)); } + | SECTION { ZEND_INI_PARSER_CB(&$1, NULL, ZEND_INI_PARSER_SECTION, ZEND_INI_PARSER_ARG); free(Z_STRVAL($1)); } | '\n' ; @@ -286,7 +286,7 @@ var_string_list: | TC_ENCAPSULATED_STRING { $$ = $1; } | constant_string { $$ = $1; } | var_string_list cfg_var_ref { zend_ini_add_string(&$$, &$1, &$2); free($2.value.str.val); } - | var_string_list TC_ENCAPSULATED_STRING { zend_ini_add_string(&$$, &$1, &$2); free($2.value.str.val); } + | var_string_list TC_ENCAPSULATED_STRING { zend_ini_add_string(&$$, &$1, &$2); free(Z_STRVAL($2)); } | var_string_list constant_string { zend_ini_add_string(&$$, &$1, &$2); free($2.value.str.val); } ; diff --git a/Zend/zend_ini_scanner.l b/Zend/zend_ini_scanner.l index e2740261d6..3f91bb64a7 100644 --- a/Zend/zend_ini_scanner.l +++ b/Zend/zend_ini_scanner.l @@ -48,6 +48,10 @@ ZEND_API ts_rsrc_id ini_scanner_globals_id; ZEND_API zend_scanner_globals ini_scanner_globals; #endif +# define YY_INPUT(buf, result, max_size) \ + if ( ((result = zend_stream_read(yyin, buf, max_size TSRMLS_CC)) == 0) \ + && zend_stream_ferror( yyin TSRMLS_CC) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); static char *ini_filename; @@ -56,19 +60,16 @@ void init_ini_scanner(TSRMLS_D) SCNG(lineno)=1; } - int zend_ini_scanner_get_lineno(TSRMLS_D) { return SCNG(lineno); } - char *zend_ini_scanner_get_filename(TSRMLS_D) { return ini_filename; } - int zend_ini_open_file_for_scanning(zend_file_handle *fh TSRMLS_DC) { if (FAILURE == zend_stream_fixup(fh TSRMLS_CC)) { @@ -82,7 +83,6 @@ int zend_ini_open_file_for_scanning(zend_file_handle *fh TSRMLS_DC) return SUCCESS; } - int zend_ini_prepare_string_for_scanning(char *str TSRMLS_DC) { int len = strlen(str); @@ -93,7 +93,6 @@ int zend_ini_prepare_string_for_scanning(char *str TSRMLS_DC) return SUCCESS; } - void zend_ini_close_file(zend_file_handle *fh TSRMLS_DC) { zend_stream_close(fh); @@ -113,17 +112,17 @@ NEWLINE ("\r"|"\n"|"\r\n") } [ ]*("true"|"on"|"yes")[ ]* { - ini_lval->value.str.val = zend_strndup("1", 1); - ini_lval->value.str.len = 1; - ini_lval->type = IS_STRING; + Z_STRVAL_P(ini_lval) = zend_strndup("1", 1); + Z_STRLEN_P(ini_lval) = 1; + Z_TYPE_P(ini_lval) = IS_STRING; return CFG_TRUE; } -[ ]*("false"|"off"|"no"|"none")[ ]* { - ini_lval->value.str.val = zend_strndup("", 0); - ini_lval->value.str.len = 0; - ini_lval->type = IS_STRING; +[ ]*("false"|"off"|"no"|"none"|"null")[ ]* { + Z_STRVAL_P(ini_lval) = zend_strndup("", 0); + Z_STRLEN_P(ini_lval) = 0; + Z_TYPE_P(ini_lval) = IS_STRING; return CFG_FALSE; } @@ -142,13 +141,12 @@ NEWLINE ("\r"|"\n"|"\r\n") yytext++; yyleng--; - ini_lval->value.str.val = zend_strndup(yytext, yyleng); - ini_lval->value.str.len = yyleng; - ini_lval->type = IS_STRING; + Z_STRVAL_P(ini_lval) = zend_strndup(yytext, yyleng); + Z_STRLEN_P(ini_lval) = yyleng; + Z_TYPE_P(ini_lval) = IS_STRING; return SECTION; } - ["][^"]*["] { char *p = yytext; @@ -168,22 +166,22 @@ NEWLINE ("\r"|"\n"|"\r\n") /* eat leading " */ yytext++; - ini_lval->value.str.val = zend_strndup(yytext, yyleng - 2); - ini_lval->value.str.len = yyleng - 2; - ini_lval->type = IS_STRING; + Z_STRVAL_P(ini_lval) = zend_strndup(yytext, yyleng - 2); + Z_STRLEN_P(ini_lval) = yyleng - 2; + Z_TYPE_P(ini_lval) = IS_STRING; return TC_ENCAPSULATED_STRING; } -[&|~$(){}!] { - return yytext[0]; -} - "${" { return TC_DOLLAR_CURLY; } "}" { - ini_lval->value.lval = (long) yytext[0]; + Z_LVAL_P(ini_lval) = (long) yytext[0]; + return yytext[0]; +} + +[&|~$(){}!] { return yytext[0]; } @@ -210,9 +208,9 @@ NEWLINE ("\r"|"\n"|"\r\n") } } if (yyleng!=0) { - ini_lval->value.str.val = zend_strndup(yytext, yyleng); - ini_lval->value.str.len = yyleng; - ini_lval->type = IS_STRING; + Z_STRVAL_P(ini_lval) = zend_strndup(yytext, yyleng); + Z_STRLEN_P(ini_lval) = yyleng; + Z_TYPE_P(ini_lval) = IS_STRING; return TC_STRING; } else { /* whitespace */ diff --git a/Zend/zend_strtod.c b/Zend/zend_strtod.c index 4c74541c91..49e14a60b2 100644 --- a/Zend/zend_strtod.c +++ b/Zend/zend_strtod.c @@ -91,6 +91,7 @@ /* $Id$ */ +#include #include #ifdef ZTS -- 2.50.1