lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <dc3f432b92d9f0679813df24de61c37f49343bdb.1528215659.git.msuchanek@suse.de>
Date:   Tue,  5 Jun 2018 18:43:11 +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 4/5] lib/cmdline.c: Implement single quotes in commandline argument parsing.

This brings the kernel parser about on par with bourne shell, grub, and
other tools that chew the arguments before kernel does.

This should make it easier to deal with multiple levels of
nesting/quoting. With same quoting grammar on each level there is less
room for confusion.

Signed-off-by: Michal Suchanek <msuchanek@...e.de>
---
- optimize end quote removal
---
 lib/cmdline.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/lib/cmdline.c b/lib/cmdline.c
index aa0086dbb082..e699ed5aac8a 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -192,19 +192,26 @@ bool parse_option_str(const char *str, const char *option)
 }
 
 #define break_arg_end(i) { \
-	if (isspace(args[i]) && !in_quote && !backslash) \
+	if (isspace(args[i]) && !in_quote && !backslash && !in_single) \
 		break; \
 	}
 
+#define squash_char { \
+	break_arg_end(i + 1); \
+	memmove(args + 1, args, i); \
+	args++; \
+	i--; \
+}
+
 /*
  * Parse a string to get a param value pair.
- * You can use " around spaces, and you can escape with \
+ * You can use " or ' 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, backslash = 0;
+	int in_quote = 0, backslash = 0, in_single = 0;
 	char *next;
 
 	for (i = 0; args[i]; i++) {
@@ -213,17 +220,23 @@ char *next_arg(char *args, char **param, char **val, int *state_flags)
 		if ((equals == 0) && (args[i] == '='))
 			equals = i;
 
-		if (!backslash) {
-			if ((args[i] == '"') || (args[i] == '\\')) {
+		if (in_single) {
+			if (args[i] == '\'') {
+				in_single = 0;
+
+				squash_char;
+			}
+		} else if (!backslash) {
+			if ((args[i] == '"') || (args[i] == '\\') ||
+					(args[i] == '\'')) {
 				if (args[i] == '"')
 					in_quote = !in_quote;
 				if (args[i] == '\\')
 					backslash = 1;
+				if (args[i] == '\'')
+					in_single = 1;
 
-				break_arg_end(i + 1);
-				memmove(args + 1, args, i);
-				args++;
-				i--;
+				squash_char;
 			}
 		} else {
 			backslash = 0;
-- 
2.13.6

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ