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