* grub-core/script/execute.c (grub_script_break): Clarify logic.
Better error handling. (grub_script_return): Likewise. * grub-core/script/lexer.c (grub_script_lexer_yywrap): Likewise.
This commit is contained in:
parent
77c9182fd2
commit
d9a62292e3
3 changed files with 35 additions and 10 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2012-02-12 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
* grub-core/script/execute.c (grub_script_break): Clarify logic.
|
||||||
|
Better error handling.
|
||||||
|
(grub_script_return): Likewise.
|
||||||
|
* grub-core/script/lexer.c (grub_script_lexer_yywrap): Likewise.
|
||||||
|
|
||||||
2012-02-12 Vladimir Serbinenko <phcoder@gmail.com>
|
2012-02-12 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* grub-core/lib/libgcrypt_wrap/cipher_wrap.h (__GNU_LIBRARY__): Avoid
|
* grub-core/lib/libgcrypt_wrap/cipher_wrap.h (__GNU_LIBRARY__): Avoid
|
||||||
|
|
|
@ -77,10 +77,18 @@ grub_script_break (grub_command_t cmd, int argc, char *argv[])
|
||||||
|
|
||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
count = 1;
|
count = 1;
|
||||||
|
else if (argc > 1)
|
||||||
else if ((argc > 1) || (count = grub_strtoul (argv[0], &p, 10)) == 0 ||
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
|
||||||
(*p != '\0'))
|
else
|
||||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad break");
|
{
|
||||||
|
count = grub_strtoul (argv[0], &p, 10);
|
||||||
|
if (grub_errno)
|
||||||
|
return grub_errno;
|
||||||
|
if (*p != '\0')
|
||||||
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unrecognized number"));
|
||||||
|
if (count == 0)
|
||||||
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't break 0 loops"));
|
||||||
|
}
|
||||||
|
|
||||||
is_continue = grub_strcmp (cmd->name, "break") ? 1 : 0;
|
is_continue = grub_strcmp (cmd->name, "break") ? 1 : 0;
|
||||||
active_breaks = count;
|
active_breaks = count;
|
||||||
|
@ -172,11 +180,14 @@ grub_script_return (grub_command_t cmd __attribute__((unused)),
|
||||||
}
|
}
|
||||||
|
|
||||||
n = grub_strtoul (argv[0], &p, 10);
|
n = grub_strtoul (argv[0], &p, 10);
|
||||||
|
if (grub_errno)
|
||||||
|
return grub_errno;
|
||||||
if (*p != '\0')
|
if (*p != '\0')
|
||||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad argument");
|
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||||
|
N_("unrecognized number"));
|
||||||
|
|
||||||
function_return = 1;
|
function_return = 1;
|
||||||
return n ? grub_error (GRUB_ERR_TEST_FAILURE, "false") : GRUB_ERR_NONE;
|
return n ? grub_error (n, N_("false")) : GRUB_ERR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -130,7 +130,7 @@ int
|
||||||
grub_script_lexer_yywrap (struct grub_parser_param *parserstate,
|
grub_script_lexer_yywrap (struct grub_parser_param *parserstate,
|
||||||
const char *input)
|
const char *input)
|
||||||
{
|
{
|
||||||
int len = 0;
|
grub_size_t len = 0;
|
||||||
char *p = 0;
|
char *p = 0;
|
||||||
char *line = 0;
|
char *line = 0;
|
||||||
YY_BUFFER_STATE buffer;
|
YY_BUFFER_STATE buffer;
|
||||||
|
@ -151,14 +151,21 @@ grub_script_lexer_yywrap (struct grub_parser_param *parserstate,
|
||||||
else
|
else
|
||||||
line = grub_strdup (input);
|
line = grub_strdup (input);
|
||||||
|
|
||||||
|
if (! line)
|
||||||
|
{
|
||||||
|
grub_script_yyerror (parserstate, N_("out of memory"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = grub_strlen (line);
|
||||||
|
|
||||||
/* Ensure '\n' at the end. */
|
/* Ensure '\n' at the end. */
|
||||||
if (line && line[0] == '\0')
|
if (line[0] == '\0')
|
||||||
{
|
{
|
||||||
grub_free (line);
|
grub_free (line);
|
||||||
line = grub_strdup ("\n");
|
line = grub_strdup ("\n");
|
||||||
}
|
}
|
||||||
|
else if (len && line[len - 1] != '\n')
|
||||||
if (line && (len = grub_strlen(line)) && line[len - 1] != '\n')
|
|
||||||
{
|
{
|
||||||
p = grub_realloc (line, len + 2);
|
p = grub_realloc (line, len + 2);
|
||||||
if (p)
|
if (p)
|
||||||
|
|
Loading…
Reference in a new issue