Fix cmdline argument quotes for setparams command of menuentry

definitions.

	* grub-core/commands/menuentry.c (setparams_prefix): Use single
	quotes for arguments.
	* grub-core/lib/legacy_parse.c (grub_legacy_escape): Use
	grub_strchrsub function instead.

	* include/grub/misc.h (grub_strchrsub): New function.
This commit is contained in:
BVK Chaitanya 2010-11-25 19:59:10 +05:30
commit 70b405d8f0
4 changed files with 51 additions and 40 deletions

View file

@ -1,3 +1,15 @@
2010-11-25 BVK Chaitanya <bvk.groups@gmail.com>
Fix cmdline argument quotes for setparams command of menuentry
definitions.
* grub-core/commands/menuentry.c (setparams_prefix): Use single
quotes for arguments.
* grub-core/lib/legacy_parse.c (grub_legacy_escape): Use
grub_strchrsub function instead.
* include/grub/misc.h (grub_strchrsub): New function.
2010-11-24 Colin Watson <cjwatson@ubuntu.com>
* util/deviceiter.c (grub_util_iterate_devices): Save a bit of

View file

@ -206,20 +206,6 @@ setparams_prefix (int argc, char **args)
char *p;
char *result;
grub_size_t len = 10;
static const char *escape_characters = "\"\\";
auto char *strescpy (char *, const char *, const char *);
char * strescpy (char *d, const char *s, const char *escapes)
{
while (*s)
{
if (grub_strchr (escapes, *s))
*d++ = '\\';
*d++ = *s++;
}
*d = '\0';
return d;
}
/* Count resulting string length */
for (i = 0; i < argc; i++)
@ -227,7 +213,7 @@ setparams_prefix (int argc, char **args)
len += 3; /* 3 = 1 space + 2 quotes */
p = args[i];
while (*p)
len += grub_strchr (escape_characters, *p++) ? 2 : 1;
len += (*p++ == '\'' ? 3 : 1);
}
result = grub_malloc (len + 2);
@ -235,17 +221,17 @@ setparams_prefix (int argc, char **args)
return 0;
grub_strcpy (result, "setparams");
i = 9;
p = result + 9;
for (j = 0; j < argc; j++)
{
result[i++] = ' ';
result[i++] = '"';
i = strescpy (result + i, args[j], escape_characters) - result;
result[i++] = '"';
*p++ = ' ';
*p++ = '\'';
p = grub_strchrsub (p, args[j], '\'', "'\\''");
*p++ = '\'';
}
result[i++] = '\n';
result[i] = '\0';
*p++ = '\n';
*p = '\0';
return result;
}

View file

@ -322,30 +322,23 @@ struct legacy_command legacy_commands[] =
char *
grub_legacy_escape (const char *in, grub_size_t len)
{
const char *ptr;
char *ret, *outptr;
char *ptr;
char *ret;
char saved;
int overhead = 0;
for (ptr = in; ptr < in + len && *ptr; ptr++)
for (ptr = (char*)in; ptr < in + len && *ptr; ptr++)
if (*ptr == '\'')
overhead += 3;
ret = grub_malloc (ptr - in + overhead + 1);
if (!ret)
return NULL;
outptr = ret;
for (ptr = in; ptr < in + len && *ptr; ptr++)
{
if (*ptr == '\'')
{
*outptr++ = '\'';
*outptr++ = '\\';
*outptr++ = '\'';
*outptr++ = '\'';
continue;
}
*outptr++ = *ptr;
}
*outptr++ = 0;
ptr = (char*)in;
saved = ptr[len];
ptr[len] = '\0';
grub_strchrsub (ret, ptr, '\'', "'\\''");
ptr[len] = saved;
return ret;
}

View file

@ -193,6 +193,26 @@ grub_strncasecmp (const char *s1, const char *s2, grub_size_t n)
return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
}
/* Replace all `ch' characters of `input' with `with' and copy the
result into `output'; return EOS address of `output'. */
static inline char *
grub_strchrsub (char *output, const char *input, char ch, const char *with)
{
grub_size_t grub_strlen (const char *s);
while (*input)
{
if (*input == ch)
{
grub_strcpy (output, with);
output += grub_strlen (with);
input++;
continue;
}
*output++ = *input++;
}
*output = '\0';
return output;
}
unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base);
unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, char **end, int base);