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