Blame SOURCES/0094-Pass-x-hex-hex-straight-through-unmolested.patch

d41074
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
a85e8e
From: Peter Jones <pjones@redhat.com>
a85e8e
Date: Mon, 1 Oct 2012 13:24:37 -0400
d41074
Subject: [PATCH] Pass "\x[[:hex:]][[:hex:]]" straight through unmolested.
a85e8e
a85e8e
---
a85e8e
 grub-core/commands/wildcard.c | 16 +++++++++++++++-
a85e8e
 grub-core/lib/cmdline.c       | 34 ++++++++++++++++++++++++++++++++--
a85e8e
 grub-core/script/execute.c    | 43 +++++++++++++++++++++++++++++++++++++------
a85e8e
 3 files changed, 84 insertions(+), 9 deletions(-)
a85e8e
a85e8e
diff --git a/grub-core/commands/wildcard.c b/grub-core/commands/wildcard.c
d41074
index 2807f806bd4..0f40e041541 100644
a85e8e
--- a/grub-core/commands/wildcard.c
a85e8e
+++ b/grub-core/commands/wildcard.c
a85e8e
@@ -458,6 +458,12 @@ check_file (const char *dir, const char *basename)
a85e8e
   return ctx.found;
a85e8e
 }
a85e8e
 
a85e8e
+static int
a85e8e
+is_hex(char c)
a85e8e
+{
a85e8e
+  return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
a85e8e
+}
a85e8e
+
a85e8e
 static void
a85e8e
 unescape (char *out, const char *in, const char *end)
a85e8e
 {
a85e8e
@@ -466,7 +472,15 @@ unescape (char *out, const char *in, const char *end)
a85e8e
 
a85e8e
   for (optr = out, iptr = in; iptr < end;)
a85e8e
     {
a85e8e
-      if (*iptr == '\\' && iptr + 1 < end)
a85e8e
+      if (*iptr == '\\' && iptr + 3 < end && iptr[1] == 'x' && is_hex(iptr[2]) && is_hex(iptr[3]))
a85e8e
+	{
a85e8e
+	  *optr++ = *iptr++;
a85e8e
+	  *optr++ = *iptr++;
a85e8e
+	  *optr++ = *iptr++;
a85e8e
+	  *optr++ = *iptr++;
a85e8e
+	  continue;
a85e8e
+	}
a85e8e
+      else if (*iptr == '\\' && iptr + 1 < end)
a85e8e
 	{
a85e8e
 	  *optr++ = iptr[1];
a85e8e
 	  iptr += 2;
a85e8e
diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c
d41074
index d5e10ee8798..0a5b2afb94b 100644
a85e8e
--- a/grub-core/lib/cmdline.c
a85e8e
+++ b/grub-core/lib/cmdline.c
a85e8e
@@ -20,6 +20,12 @@
a85e8e
 #include <grub/lib/cmdline.h>
a85e8e
 #include <grub/misc.h>
a85e8e
 
a85e8e
+static int
a85e8e
+is_hex(char c)
a85e8e
+{
a85e8e
+  return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
a85e8e
+}
a85e8e
+
a85e8e
 static unsigned int check_arg (char *c, int *has_space)
a85e8e
 {
a85e8e
   int space = 0;
a85e8e
@@ -27,7 +33,13 @@ static unsigned int check_arg (char *c, int *has_space)
a85e8e
 
a85e8e
   while (*c)
a85e8e
     {
a85e8e
-      if (*c == '\\' || *c == '\'' || *c == '"')
a85e8e
+      if (*c == '\\' && *(c+1) == 'x' && is_hex(*(c+2)) && is_hex(*(c+3)))
a85e8e
+	{
a85e8e
+	  size += 4;
a85e8e
+	  c += 4;
a85e8e
+	  continue;
a85e8e
+	}
a85e8e
+      else if (*c == '\\' || *c == '\'' || *c == '"')
a85e8e
 	size++;
a85e8e
       else if (*c == ' ')
a85e8e
 	space = 1;
a85e8e
@@ -85,7 +97,25 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
a85e8e
 
a85e8e
       while (*c)
a85e8e
 	{
a85e8e
-	  if (*c == '\\' || *c == '\'' || *c == '"')
a85e8e
+	  if (*c == ' ')
a85e8e
+	    {
a85e8e
+	      *buf++ = '\\';
a85e8e
+	      *buf++ = 'x';
a85e8e
+	      *buf++ = '2';
a85e8e
+	      *buf++ = '0';
a85e8e
+	      c++;
a85e8e
+	      continue;
a85e8e
+	    }
a85e8e
+	  else if (*c == '\\' && *(c+1) == 'x' &&
a85e8e
+		   is_hex(*(c+2)) && is_hex(*(c+3)))
a85e8e
+	    {
a85e8e
+	      *buf++ = *c++;
a85e8e
+	      *buf++ = *c++;
a85e8e
+	      *buf++ = *c++;
a85e8e
+	      *buf++ = *c++;
a85e8e
+	      continue;
a85e8e
+	    }
a85e8e
+	  else if (*c == '\\' || *c == '\'' || *c == '"')
a85e8e
 	    *buf++ = '\\';
a85e8e
 
a85e8e
 	  *buf++ = *c;
a85e8e
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
d41074
index afd551320f7..8f01c1bbfa2 100644
a85e8e
--- a/grub-core/script/execute.c
a85e8e
+++ b/grub-core/script/execute.c
a85e8e
@@ -52,6 +52,12 @@ static struct grub_script_scope *scope = 0;
a85e8e
 /* Wildcard translator for GRUB script.  */
a85e8e
 struct grub_script_wildcard_translator *grub_wildcard_translator;
a85e8e
 
a85e8e
+static int
a85e8e
+is_hex(char c)
a85e8e
+{
a85e8e
+  return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
a85e8e
+}
a85e8e
+
a85e8e
 static char*
a85e8e
 wildcard_escape (const char *s)
a85e8e
 {
a85e8e
@@ -68,7 +74,15 @@ wildcard_escape (const char *s)
a85e8e
   i = 0;
a85e8e
   while ((ch = *s++))
a85e8e
     {
a85e8e
-      if (ch == '*' || ch == '\\' || ch == '?')
a85e8e
+      if (ch == '\\' && s[0] == 'x' && is_hex(s[1]) && is_hex(s[2]))
a85e8e
+	{
a85e8e
+	  p[i++] = ch;
a85e8e
+	  p[i++] = *s++;
a85e8e
+	  p[i++] = *s++;
a85e8e
+	  p[i++] = *s++;
a85e8e
+	  continue;
a85e8e
+	}
a85e8e
+      else if (ch == '*' || ch == '\\' || ch == '?')
a85e8e
 	p[i++] = '\\';
a85e8e
       p[i++] = ch;
a85e8e
     }
a85e8e
@@ -92,7 +106,14 @@ wildcard_unescape (const char *s)
a85e8e
   i = 0;
a85e8e
   while ((ch = *s++))
a85e8e
     {
a85e8e
-      if (ch == '\\')
a85e8e
+      if (ch == '\\' && s[0] == 'x' && is_hex(s[1]) && is_hex(s[2]))
a85e8e
+	{
a85e8e
+	  p[i++] = '\\';
a85e8e
+	  p[i++] = *s++;
a85e8e
+	  p[i++] = *s++;
a85e8e
+	  p[i++] = *s++;
a85e8e
+	}
a85e8e
+      else if (ch == '\\')
a85e8e
 	p[i++] = *s++;
a85e8e
       else
a85e8e
 	p[i++] = ch;
a85e8e
@@ -394,10 +415,20 @@ parse_string (const char *str,
a85e8e
     switch (*ptr)
a85e8e
       {
a85e8e
       case '\\':
a85e8e
-	escaped = !escaped;
a85e8e
-	if (!escaped && put)
a85e8e
-	  *(put++) = '\\';
a85e8e
-	ptr++;
a85e8e
+	if (!escaped && put && *(ptr+1) == 'x' && is_hex(*(ptr+2)) && is_hex(*(ptr+3)))
a85e8e
+	  {
a85e8e
+	    *(put++) = *ptr++;
a85e8e
+	    *(put++) = *ptr++;
a85e8e
+	    *(put++) = *ptr++;
a85e8e
+	    *(put++) = *ptr++;
a85e8e
+	  }
a85e8e
+	else
a85e8e
+	  {
a85e8e
+	    escaped = !escaped;
a85e8e
+	    if (!escaped && put)
a85e8e
+	      *(put++) = '\\';
a85e8e
+	    ptr++;
a85e8e
+	  }
a85e8e
 	break;
a85e8e
       case '$':
a85e8e
 	if (escaped)