diff --git a/ChangeLog b/ChangeLog index bb9c120a7..bfed63980 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2012-02-12 Vladimir Serbinenko + + * 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 * grub-core/lib/libgcrypt_wrap/cipher_wrap.h (__GNU_LIBRARY__): Avoid diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c index a95e1b6a0..27968e182 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -77,10 +77,18 @@ grub_script_break (grub_command_t cmd, int argc, char *argv[]) if (argc == 0) count = 1; - - else if ((argc > 1) || (count = grub_strtoul (argv[0], &p, 10)) == 0 || - (*p != '\0')) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad break"); + else if (argc > 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); + else + { + 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; active_breaks = count; @@ -172,11 +180,14 @@ grub_script_return (grub_command_t cmd __attribute__((unused)), } n = grub_strtoul (argv[0], &p, 10); + if (grub_errno) + return grub_errno; 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; - return n ? grub_error (GRUB_ERR_TEST_FAILURE, "false") : GRUB_ERR_NONE; + return n ? grub_error (n, N_("false")) : GRUB_ERR_NONE; } static int diff --git a/grub-core/script/lexer.c b/grub-core/script/lexer.c index 54d33cfd5..396d51277 100644 --- a/grub-core/script/lexer.c +++ b/grub-core/script/lexer.c @@ -130,7 +130,7 @@ int grub_script_lexer_yywrap (struct grub_parser_param *parserstate, const char *input) { - int len = 0; + grub_size_t len = 0; char *p = 0; char *line = 0; YY_BUFFER_STATE buffer; @@ -151,14 +151,21 @@ grub_script_lexer_yywrap (struct grub_parser_param *parserstate, else 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. */ - if (line && line[0] == '\0') + if (line[0] == '\0') { grub_free (line); line = grub_strdup ("\n"); } - - if (line && (len = grub_strlen(line)) && line[len - 1] != '\n') + else if (len && line[len - 1] != '\n') { p = grub_realloc (line, len + 2); if (p)