dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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