removed arbitrary limit on token size
This commit is contained in:
parent
547e494f1b
commit
df6dc2113a
3 changed files with 89 additions and 81 deletions
|
@ -157,8 +157,10 @@ struct grub_lexer_param
|
||||||
int merge_start;
|
int merge_start;
|
||||||
int merge_end;
|
int merge_end;
|
||||||
|
|
||||||
/* Text of current token. */
|
/* Part of a multi-part token. */
|
||||||
char *text;
|
char *text;
|
||||||
|
unsigned used;
|
||||||
|
unsigned size;
|
||||||
|
|
||||||
/* Type of text. */
|
/* Type of text. */
|
||||||
grub_script_arg_type_t type;
|
grub_script_arg_type_t type;
|
||||||
|
@ -168,12 +170,9 @@ struct grub_lexer_param
|
||||||
|
|
||||||
/* Flex scanner buffer. */
|
/* Flex scanner buffer. */
|
||||||
void *buffer;
|
void *buffer;
|
||||||
|
|
||||||
/* Length of current token text. */
|
|
||||||
unsigned size;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define GRUB_LEXER_TOKEN_MAX 256
|
#define GRUB_LEXER_INITIAL_TEXT_SIZE 32
|
||||||
#define GRUB_LEXER_RECORD_INCREMENT 256
|
#define GRUB_LEXER_RECORD_INCREMENT 256
|
||||||
|
|
||||||
/* State of the parser as passes to the parser. */
|
/* State of the parser as passes to the parser. */
|
||||||
|
|
|
@ -213,7 +213,8 @@ grub_script_lexer_init (struct grub_parser_param *parser, char *script,
|
||||||
if (!lexerstate)
|
if (!lexerstate)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
lexerstate->text = grub_malloc (GRUB_LEXER_TOKEN_MAX);
|
lexerstate->size = GRUB_LEXER_INITIAL_TEXT_SIZE;
|
||||||
|
lexerstate->text = grub_malloc (lexerstate->size);
|
||||||
if (!lexerstate->text)
|
if (!lexerstate->text)
|
||||||
{
|
{
|
||||||
grub_free (lexerstate);
|
grub_free (lexerstate);
|
||||||
|
@ -301,7 +302,7 @@ grub_script_yylex (union YYSTYPE *value,
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* Empty lexerstate->text. */
|
/* Empty lexerstate->text. */
|
||||||
lexerstate->size = 0;
|
lexerstate->used = 1;
|
||||||
lexerstate->text[0] = '\0';
|
lexerstate->text[0] = '\0';
|
||||||
|
|
||||||
token = yylex (value, lexerstate->yyscanner);
|
token = yylex (value, lexerstate->yyscanner);
|
||||||
|
@ -311,7 +312,6 @@ grub_script_yylex (union YYSTYPE *value,
|
||||||
/* Merging feature uses lexerstate->text instead of yytext. */
|
/* Merging feature uses lexerstate->text instead of yytext. */
|
||||||
if (lexerstate->merge_start)
|
if (lexerstate->merge_start)
|
||||||
{
|
{
|
||||||
lexerstate->text[lexerstate->size] = '\0';
|
|
||||||
str = lexerstate->text;
|
str = lexerstate->text;
|
||||||
type = lexerstate->type;
|
type = lexerstate->type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,23 +37,11 @@
|
||||||
grub_printf ("fatal error: %s\n", msg); \
|
grub_printf ("fatal error: %s\n", msg); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define PUSH(c) \
|
#define COPY(str, hint) \
|
||||||
do { \
|
do { \
|
||||||
if (yyextra->lexerstate->size >= GRUB_LEXER_TOKEN_MAX - 1) \
|
copy_string (yyextra, str, hint); \
|
||||||
grub_script_yyerror (yyextra, "token too long"); \
|
|
||||||
else \
|
|
||||||
yyextra->lexerstate->text[yyextra->lexerstate->size++] = c; \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define COPY(str) \
|
|
||||||
do { \
|
|
||||||
char *ptr = str; \
|
|
||||||
while (*ptr && ! yyextra->err) \
|
|
||||||
{ \
|
|
||||||
PUSH (*ptr); \
|
|
||||||
ptr++; \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define RECORD \
|
#define RECORD \
|
||||||
do { \
|
do { \
|
||||||
|
@ -73,6 +61,8 @@
|
||||||
static void grub_lexer_yyfree (void *, yyscan_t yyscanner);
|
static void grub_lexer_yyfree (void *, yyscan_t yyscanner);
|
||||||
static void* grub_lexer_yyalloc (yy_size_t, yyscan_t yyscanner);
|
static void* grub_lexer_yyalloc (yy_size_t, yyscan_t yyscanner);
|
||||||
static void* grub_lexer_yyrealloc (void*, yy_size_t, yyscan_t yyscanner);
|
static void* grub_lexer_yyrealloc (void*, yy_size_t, yyscan_t yyscanner);
|
||||||
|
static void copy_string (struct grub_parser_param *, const char *,
|
||||||
|
unsigned hint);
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
@ -223,7 +213,7 @@ WORD ({CHAR}|{DQSTR}|{SQSTR}|{ESC}|{VARIABLE})+
|
||||||
/* Split word into multiple args */
|
/* Split word into multiple args */
|
||||||
|
|
||||||
<SPLIT>{
|
<SPLIT>{
|
||||||
\\. { PUSH (yytext[1]); }
|
\\. { COPY (yytext + 1, yyleng - 1); }
|
||||||
\" {
|
\" {
|
||||||
yy_push_state (DQUOTE, yyscanner);
|
yy_push_state (DQUOTE, yyscanner);
|
||||||
ARG (GRUB_SCRIPT_ARG_TYPE_TEXT);
|
ARG (GRUB_SCRIPT_ARG_TYPE_TEXT);
|
||||||
|
@ -236,13 +226,8 @@ WORD ({CHAR}|{DQSTR}|{SQSTR}|{ESC}|{VARIABLE})+
|
||||||
yy_push_state (VAR, yyscanner);
|
yy_push_state (VAR, yyscanner);
|
||||||
ARG (GRUB_SCRIPT_ARG_TYPE_TEXT);
|
ARG (GRUB_SCRIPT_ARG_TYPE_TEXT);
|
||||||
}
|
}
|
||||||
{CHAR} { PUSH (yytext[0]); }
|
\\ |
|
||||||
.|\n {
|
[^\"\'$\\]+ { COPY (yytext, yyleng); }
|
||||||
/* This cannot happen. */
|
|
||||||
grub_script_yyerror (yyextra, "internal error: unexpected characters in a word");
|
|
||||||
return GRUB_PARSER_TOKEN_BAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
<<EOF>> {
|
<<EOF>> {
|
||||||
yy_pop_state (yyscanner);
|
yy_pop_state (yyscanner);
|
||||||
yypop_buffer_state (yyscanner);
|
yypop_buffer_state (yyscanner);
|
||||||
|
@ -255,7 +240,7 @@ WORD ({CHAR}|{DQSTR}|{SQSTR}|{ESC}|{VARIABLE})+
|
||||||
\? |
|
\? |
|
||||||
{DIGITS} |
|
{DIGITS} |
|
||||||
{NAME} {
|
{NAME} {
|
||||||
COPY (yytext);
|
COPY (yytext, yyleng);
|
||||||
yy_pop_state (yyscanner);
|
yy_pop_state (yyscanner);
|
||||||
if (YY_START == SPLIT)
|
if (YY_START == SPLIT)
|
||||||
ARG (GRUB_SCRIPT_ARG_TYPE_VAR);
|
ARG (GRUB_SCRIPT_ARG_TYPE_VAR);
|
||||||
|
@ -266,7 +251,7 @@ WORD ({CHAR}|{DQSTR}|{SQSTR}|{ESC}|{VARIABLE})+
|
||||||
\{{DIGITS}\} |
|
\{{DIGITS}\} |
|
||||||
\{{NAME}\} {
|
\{{NAME}\} {
|
||||||
yytext[yyleng - 1] = '\0';
|
yytext[yyleng - 1] = '\0';
|
||||||
COPY (yytext + 1);
|
COPY (yytext + 1, yyleng - 2);
|
||||||
yy_pop_state (yyscanner);
|
yy_pop_state (yyscanner);
|
||||||
if (YY_START == SPLIT)
|
if (YY_START == SPLIT)
|
||||||
ARG (GRUB_SCRIPT_ARG_TYPE_VAR);
|
ARG (GRUB_SCRIPT_ARG_TYPE_VAR);
|
||||||
|
@ -281,7 +266,7 @@ WORD ({CHAR}|{DQSTR}|{SQSTR}|{ESC}|{VARIABLE})+
|
||||||
yy_pop_state (yyscanner);
|
yy_pop_state (yyscanner);
|
||||||
ARG (GRUB_SCRIPT_ARG_TYPE_SQSTR);
|
ARG (GRUB_SCRIPT_ARG_TYPE_SQSTR);
|
||||||
}
|
}
|
||||||
(.|\n) { PUSH (yytext[0]); }
|
[^\']+ { COPY (yytext, yyleng); }
|
||||||
}
|
}
|
||||||
|
|
||||||
<DQUOTE>{
|
<DQUOTE>{
|
||||||
|
@ -293,10 +278,11 @@ WORD ({CHAR}|{DQSTR}|{SQSTR}|{ESC}|{VARIABLE})+
|
||||||
yy_push_state (VAR, yyscanner);
|
yy_push_state (VAR, yyscanner);
|
||||||
ARG (GRUB_SCRIPT_ARG_TYPE_DQSTR);
|
ARG (GRUB_SCRIPT_ARG_TYPE_DQSTR);
|
||||||
}
|
}
|
||||||
\\\\ { PUSH ('\\'); }
|
\\\\ { COPY ("\\", 1); }
|
||||||
\\\" { PUSH ('\"'); }
|
\\\" { COPY ("\"", 1); }
|
||||||
\\\n { /* ignore */ }
|
\\\n { /* ignore */ }
|
||||||
(.|\n) { PUSH (yytext[0]); }
|
[^\"$\\\n]+ { COPY (yytext, yyleng); }
|
||||||
|
(.|\n) { COPY (yytext, yyleng); }
|
||||||
}
|
}
|
||||||
|
|
||||||
<<EOF>> {
|
<<EOF>> {
|
||||||
|
@ -329,3 +315,26 @@ grub_lexer_yyrealloc (void *ptr, yy_size_t size,
|
||||||
return grub_realloc (ptr, size);
|
return grub_realloc (ptr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void copy_string (struct grub_parser_param *parser, const char *str, unsigned hint)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
int size;
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
len = hint ? hint : grub_strlen (str);
|
||||||
|
if (parser->lexerstate->used + len >= parser->lexerstate->size)
|
||||||
|
{
|
||||||
|
size = parser->lexerstate->size * 2;
|
||||||
|
ptr = grub_realloc (parser->lexerstate->text, size);
|
||||||
|
if (!ptr)
|
||||||
|
{
|
||||||
|
grub_script_yyerror (parser, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser->lexerstate->text = ptr;
|
||||||
|
parser->lexerstate->size = size;
|
||||||
|
}
|
||||||
|
grub_strcpy (parser->lexerstate->text + parser->lexerstate->used - 1, str);
|
||||||
|
parser->lexerstate->used += len;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue