+2009-06-17 Vladimir Serbinenko <phcoder@gmail.com>
+
+ Fix newline handling
+
+ * include/grub/script_sh.h (grub_lexer_param): new field was_newline
+ * script/sh/lexer.c (grub_script_lexer_init): initilaise was_newline
+ (grub_script_yylex): don't segfault on unterminated script
+ newline terminates command and variable
+
2009-06-17 Vladimir Serbinenko <phcoder@gmail.com>
avoid double grub_adjust_range call. Bug reported by David Simner
param->recordpos = 0;
param->recordlen = 0;
param->tokenonhold = 0;
+ param->was_newline = 0;
return param;
}
for (;! state->done; firstrun = 0)
{
-
- if (! *state->script)
+ if (! state->script || ! *state->script)
{
/* Check if more tokens are requested by the parser. */
if (((state->refs && ! parsestate->err)
&& state->getline)
{
int doexit = 0;
- while (!state->script || ! *state->script)
+ if (state->state != GRUB_PARSER_STATE_ESC
+ && state->state != GRUB_PARSER_STATE_QUOTE
+ && state->state != GRUB_PARSER_STATE_DQUOTE
+ && ! state->was_newline)
+ {
+ state->was_newline = 1;
+ state->tokenonhold = '\n';
+ break;
+ }
+ while (! state->script || ! *state->script)
{
grub_free (state->newscript);
state->newscript = 0;
break;
grub_dprintf ("scripting", "token=`\\n'\n");
recordchar (state, '\n');
- if (state->state != GRUB_PARSER_STATE_ESC
- && state->state != GRUB_PARSER_STATE_DQUOTE
- && state->state != GRUB_PARSER_STATE_QUOTE)
- {
- state->tokenonhold = '\n';
- break;
- }
+ if (state->state == GRUB_PARSER_STATE_VARNAME)
+ state->state = GRUB_PARSER_STATE_TEXT;
+ if (state->state == GRUB_PARSER_STATE_QVARNAME)
+ state->state = GRUB_PARSER_STATE_DQUOTE;
if (state->state == GRUB_PARSER_STATE_DQUOTE
|| state->state == GRUB_PARSER_STATE_QUOTE)
yylval->arg = grub_script_arg_add (parsestate, yylval->arg,
break;
}
}
+ state->was_newline = 0;
newstate = grub_parser_cmdline_state (state->state, *state->script, &use);