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