From: Vladimir 'phcoder' Serbinenko Date: Mon, 29 Apr 2013 10:02:26 +0000 (+0200) Subject: * grub-core/script/execute.c (grub_script_arglist_to_argv): Fix X-Git-Tag: grub-2.02-beta1~1077 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bdc4add8ca278ed8c5348fd7e7028ae6092089ef;p=thirdparty%2Fgrub.git * grub-core/script/execute.c (grub_script_arglist_to_argv): Fix handling of variables containing backslash. --- diff --git a/ChangeLog b/ChangeLog index bf413de63..9dacb19b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-04-29 Vladimir Serbinenko + + * grub-core/script/execute.c (grub_script_arglist_to_argv): Fix + handling of variables containing backslash. + 2013-04-29 Vladimir Serbinenko * include/grub/list.h (FOR_LIST_ELEMENTS_SAFE):Fix a NULL pointer diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c index a1dcc342d..9babbeee2 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -643,9 +643,38 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist, if (arg->type == GRUB_SCRIPT_ARG_TYPE_VAR) { - if (grub_script_argv_append (&result, values[i], - grub_strlen (values[i]))) + int len; + char ch; + char *p; + char *op; + const char *s = values[i]; + + len = grub_strlen (values[i]); + /* \? -> \\\? */ + /* \* -> \\\* */ + /* \ -> \\ */ + p = grub_malloc (len * 2 + 1); + if (! p) goto fail; + + op = p; + while ((ch = *s++)) + { + if (ch == '\\') + { + *op++ = '\\'; + if (*s == '?' || *s == '*') + *op++ = '\\'; + } + *op++ = ch; + } + *op = '\0'; + + if (grub_script_argv_append (&result, p, op - p)) + { + grub_free (p); + goto fail; + } } else {