2009-12-20 Vladimir Serbinenko <phcoder@gmail.com>

* kern/parser.c (grub_parser_split_cmdline): Fix incorrect counting
	of arguments. Return number of tokens and not arguments. All users
	updated.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2009-12-20 22:54:12 +01:00
parent de15bf8e7f
commit 3041d8989c
4 changed files with 26 additions and 10 deletions

View file

@ -1,3 +1,9 @@
2009-12-20 Vladimir Serbinenko <phcoder@gmail.com>
* kern/parser.c (grub_parser_split_cmdline): Fix incorrect counting
of arguments. Return number of tokens and not arguments. All users
updated.
2009-12-20 Vladimir Serbinenko <phcoder@gmail.com> 2009-12-20 Vladimir Serbinenko <phcoder@gmail.com>
* util/i386/pc/grub-setup.c (setup): Don't install on non-GPT, * util/i386/pc/grub-setup.c (setup): Don't install on non-GPT,

View file

@ -142,7 +142,7 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
*(bp++) = *val; *(bp++) = *val;
} }
*argc = 1; *argc = 0;
do do
{ {
if (! *rd) if (! *rd)
@ -188,12 +188,16 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
state = newstate; state = newstate;
} }
} while (state != GRUB_PARSER_STATE_TEXT && !check_varstate (state)); } while (state != GRUB_PARSER_STATE_TEXT && !check_varstate (state));
*(bp++) = '\0';
/* A special case for when the last character was part of a /* A special case for when the last character was part of a
variable. */ variable. */
add_var (GRUB_PARSER_STATE_TEXT); add_var (GRUB_PARSER_STATE_TEXT);
if (bp != buffer && *(bp - 1))
{
*(bp++) = '\0';
(*argc)++;
}
/* Reserve memory for the return values. */ /* Reserve memory for the return values. */
args = grub_malloc (bp - buffer); args = grub_malloc (bp - buffer);
@ -219,8 +223,6 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
bp++; bp++;
} }
(*argc)--;
return 0; return 0;
} }

View file

@ -35,9 +35,12 @@ grub_rescue_parse_line (char *line, grub_reader_getline_t getline)
if (grub_parser_split_cmdline (line, getline, &n, &args) || n < 0) if (grub_parser_split_cmdline (line, getline, &n, &args) || n < 0)
return grub_errno; return grub_errno;
if (n == 0)
return GRUB_ERR_NONE;
/* In case of an assignment set the environment accordingly /* In case of an assignment set the environment accordingly
instead of calling a function. */ instead of calling a function. */
if (n == 0 && grub_strchr (line, '=')) if (n == 1 && grub_strchr (line, '='))
{ {
char *val = grub_strchr (args[0], '='); char *val = grub_strchr (args[0], '=');
val[0] = 0; val[0] = 0;
@ -56,7 +59,7 @@ grub_rescue_parse_line (char *line, grub_reader_getline_t getline)
cmd = grub_command_find (name); cmd = grub_command_find (name);
if (cmd) if (cmd)
{ {
(cmd->func) (cmd, n, &args[1]); (cmd->func) (cmd, n - 1, &args[1]);
} }
else else
{ {

View file

@ -409,13 +409,16 @@ grub_normal_do_completion (char *buf, int *restore,
if (grub_parser_split_cmdline (buf, 0, &argc, &argv)) if (grub_parser_split_cmdline (buf, 0, &argc, &argv))
return 0; return 0;
current_word = argv[argc]; if (argc == 0)
current_word = "";
else
current_word = argv[argc - 1];
/* Determine the state the command line is in, depending on the /* Determine the state the command line is in, depending on the
state, it can be determined how to complete. */ state, it can be determined how to complete. */
cmdline_state = get_state (buf); cmdline_state = get_state (buf);
if (argc == 0) if (argc == 1 || argc == 0)
{ {
/* Complete a command. */ /* Complete a command. */
if (grub_command_iterate (iterate_command)) if (grub_command_iterate (iterate_command))
@ -485,13 +488,15 @@ grub_normal_do_completion (char *buf, int *restore,
goto fail; goto fail;
} }
grub_free (argv[0]); if (argc != 0)
grub_free (argv[0]);
grub_free (match); grub_free (match);
return ret; return ret;
} }
fail: fail:
grub_free (argv[0]); if (argc != 0)
grub_free (argv[0]);
grub_free (match); grub_free (match);
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;