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