From d060ad60eee798a5c7c970ca2e777c7f1d0f8caa Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 21 Dec 2010 13:52:07 +0000 Subject: [PATCH] * grub-core/commands/echo.c (grub_cmd_echo): Make UTF-8-clean by constructing a new unescaped string and passing it to grub_xputs in one go, rather than passing characters to grub_printf one at a time. --- ChangeLog | 6 ++++++ grub-core/commands/echo.c | 26 ++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 42e059d46..e65dc231c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-21 Colin Watson + + * grub-core/commands/echo.c (grub_cmd_echo): Make UTF-8-clean by + constructing a new unescaped string and passing it to grub_xputs in + one go, rather than passing characters to grub_printf one at a time. + 2010-12-21 Colin Watson * grub-core/fs/udf.c (read_string): Pacify GCC warning by diff --git a/grub-core/commands/echo.c b/grub-core/commands/echo.c index 7ab9f92c6..93a452fc8 100644 --- a/grub-core/commands/echo.c +++ b/grub-core/commands/echo.c @@ -44,8 +44,14 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args) for (i = 0; i < argc; i++) { char *arg = *args; + /* Unescaping results in a string no longer than the original. */ + char *unescaped = grub_malloc (grub_strlen (arg) + 1); + char *p = unescaped; args++; + if (!unescaped) + return grub_errno; + while (*arg) { /* In case `-e' is used, parse backslashes. */ @@ -58,11 +64,11 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args) switch (*arg) { case '\\': - grub_printf ("\\"); + *p++ = '\\'; break; case 'a': - grub_printf ("\a"); + *p++ = '\a'; break; case 'c': @@ -70,23 +76,23 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args) break; case 'f': - grub_printf ("\f"); + *p++ = '\f'; break; case 'n': - grub_printf ("\n"); + *p++ = '\n'; break; case 'r': - grub_printf ("\r"); + *p++ = '\r'; break; case 't': - grub_printf ("\t"); + *p++ = '\t'; break; case 'v': - grub_printf ("\v"); + *p++ = '\v'; break; } arg++; @@ -95,10 +101,14 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args) /* This was not an escaped character, or escaping is not enabled. */ - grub_printf ("%c", *arg); + *p++ = *arg; arg++; } + *p = '\0'; + grub_xputs (unescaped); + grub_free (unescaped); + /* If another argument follows, insert a space. */ if (i != argc - 1) grub_printf (" " );