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

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