Fix quoting in legacy parser.

* grub-core/lib/legacy_parse.c (grub_legacy_escape): Correctly handle
	single quotes.
	(grub_legacy_parse): Likewise.
	Reported by: Jordan Uggla.
	Tested by: Jordan Uggla.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-11-15 00:33:28 +01:00
parent 03f80960cf
commit 22e7dbb2bb
2 changed files with 32 additions and 9 deletions

View file

@ -1,3 +1,13 @@
2010-11-14 Vladimir Serbinenko <phcoder@gmail.com>
Fix quoting in legacy parser.
* grub-core/lib/legacy_parse.c (grub_legacy_escape): Correctly handle
single quotes.
(grub_legacy_parse): Likewise.
Reported by: Jordan Uggla.
Tested by: Jordan Uggla.
2010-11-14 Vladimir Serbinenko <phcoder@gmail.com>
Don't add -lgcc on i386 and x86_64.

View file

@ -326,16 +326,22 @@ grub_legacy_escape (const char *in, grub_size_t len)
char *ret, *outptr;
int overhead = 0;
for (ptr = in; ptr < in + len && *ptr; ptr++)
if (*ptr == '\'' || *ptr == '\\')
overhead++;
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 == '\'' || *ptr == '\\')
*outptr++ = '\\';
if (*ptr == '\'')
{
*outptr++ = '\'';
*outptr++ = '\\';
*outptr++ = '\'';
*outptr++ = '\'';
continue;
}
*outptr++ = *ptr;
}
@ -622,12 +628,13 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
{
for (; *ptr && grub_isspace (*ptr); ptr++);
for (; *ptr && !grub_isspace (*ptr); ptr++)
if (*ptr == '\\' || *ptr == '\'')
overhead++;
if (*ptr == '\'')
overhead += 3;
if (*ptr)
ptr++;
overhead += 3;
}
outptr0 = args[i] = grub_malloc (overhead + (ptr - curarg));
if (!outptr0)
return NULL;
@ -641,9 +648,15 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
*outptr++ = '\'';
for (; *ptr && !grub_isspace (*ptr); ptr++)
{
if (*ptr == '\\' || *ptr == '\'')
*outptr++ = '\\';
*outptr++ = *ptr;
if (*ptr == '\'')
{
*outptr++ = '\'';
*outptr++ = '\\';
*outptr++ = '\'';
*outptr++ = '\'';
}
else
*outptr++ = *ptr;
}
*outptr++ = '\'';
if (*ptr)