diff --git a/ChangeLog b/ChangeLog index 19b6631fd..7c33d8cc6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-11-14 Vladimir Serbinenko + + 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 Don't add -lgcc on i386 and x86_64. diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c index cd3bc8d40..5a359ff1c 100644 --- a/grub-core/lib/legacy_parse.c +++ b/grub-core/lib/legacy_parse.c @@ -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)