]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Fix quoting in legacy parser.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 14 Nov 2010 23:33:28 +0000 (00:33 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 14 Nov 2010 23:33:28 +0000 (00:33 +0100)
* 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.

ChangeLog
grub-core/lib/legacy_parse.c

index 19b6631fdb9f3f1ed218b9af6569bca0166aa295..7c33d8cc6b6a8d2bc72ee9529ad74f6bc5362615 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index cd3bc8d40c7ff9afe8fc8222572a18c1b6be73b8..5a359ff1c7e560c6a12b5d022fc1c0f827e4500a 100644 (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)