[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <0005cec6acaf7ef629a64a1a72b09f68f84aae4c.1528215659.git.msuchanek@suse.de>
Date: Tue, 5 Jun 2018 18:43:08 +0200
From: Michal Suchanek <msuchanek@...e.de>
To: Jonathan Corbet <corbet@....net>,
Michal Suchanek <msuchanek@...e.de>,
Arnd Bergmann <arnd@...db.de>,
Frederic Weisbecker <frederic@...nel.org>,
Ingo Molnar <mingo@...nel.org>, Aaron Wu <Aaron.Wu@...log.com>,
Tony Luck <tony.luck@...el.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Thomas Gleixner <tglx@...utronix.de>,
"Steven Rostedt," <rostedt@...dmis.org>,
Laura Abbott <lauraa@...eaurora.org>,
Dominik Brodowski <linux@...inikbrodowski.net>,
Alexey Dobriyan <adobriyan@...il.com>,
Tom Lendacky <thomas.lendacky@....com>,
Jeffrey Hugo <jhugo@...eaurora.org>,
Baoquan He <bhe@...hat.com>,
Ilya Matveychikov <matvejchikov@...il.com>,
linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH v10 1/5] lib/cmdline.c: Add backslash support to kernel commandline parsing.
- add \ as quoting character in kernel parameters
- generalize quoting character removal to be able to remove quoting
character at any position in kernel parameter rather than start and end
only
This allows passing quotes in kernel arguments.
It is also useful to have quoting grammar more similar to shells and
bootloaders.
Signed-off-by: Michal Suchanek <msuchanek@...e.de>
---
- more verbose commit message
- optimize final quote removal
---
lib/cmdline.c | 50 ++++++++++++++++++++++++++------------------------
1 file changed, 26 insertions(+), 24 deletions(-)
diff --git a/lib/cmdline.c b/lib/cmdline.c
index 192848d880ea..aa0086dbb082 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -191,32 +191,43 @@ bool parse_option_str(const char *str, const char *option)
return false;
}
+#define break_arg_end(i) { \
+ if (isspace(args[i]) && !in_quote && !backslash) \
+ break; \
+ }
+
/*
* Parse a string to get a param value pair.
- * You can use " around spaces, but can't escape ".
+ * You can use " around spaces, and you can escape with \
* Hyphens and underscores equivalent in parameter names.
*/
char *next_arg(char *args, char **param, char **val, int *state_flags)
{
unsigned int i, equals = 0;
- int in_quote = 0, quoted = 0;
+ int in_quote = 0, backslash = 0;
char *next;
- if (*args == '"') {
- args++;
- in_quote = 1;
- quoted = 1;
- }
-
for (i = 0; args[i]; i++) {
- if (isspace(args[i]) && !in_quote)
- break;
- if (equals == 0) {
- if (args[i] == '=')
- equals = i;
+ break_arg_end(i);
+
+ if ((equals == 0) && (args[i] == '='))
+ equals = i;
+
+ if (!backslash) {
+ if ((args[i] == '"') || (args[i] == '\\')) {
+ if (args[i] == '"')
+ in_quote = !in_quote;
+ if (args[i] == '\\')
+ backslash = 1;
+
+ break_arg_end(i + 1);
+ memmove(args + 1, args, i);
+ args++;
+ i--;
+ }
+ } else {
+ backslash = 0;
}
- if (args[i] == '"')
- in_quote = !in_quote;
}
if (state_flags)
@@ -231,16 +242,7 @@ char *next_arg(char *args, char **param, char **val, int *state_flags)
else {
args[equals] = '\0';
*val = args + equals + 1;
-
- /* Don't include quotes in value. */
- if (**val == '"') {
- (*val)++;
- if (args[i-1] == '"')
- args[i-1] = '\0';
- }
}
- if (quoted && args[i-1] == '"')
- args[i-1] = '\0';
if (args[i]) {
args[i] = '\0';
--
2.13.6
Powered by blists - more mailing lists