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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <151075904367.14434.5164139208561977016.stgit@hbathini.in.ibm.com>
Date:   Wed, 15 Nov 2017 20:47:25 +0530
From:   Hari Bathini <hbathini@...ux.vnet.ibm.com>
To:     linuxppc-dev <linuxppc-dev@...abs.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        lkml <linux-kernel@...r.kernel.org>
Cc:     Michael Ellerman <mpe@...erman.id.au>,
        Ankit Kumar <ankit@...ux.vnet.ibm.com>,
        Michal Suchánek <msuchanek@...e.de>,
        Mahesh J Salgaonkar <mahesh@...ux.vnet.ibm.com>
Subject: [PATCH v9 3/8] lib/cmdline.c: add backslash support to kernel
 commandline parsing

From: Michal Suchanek <msuchanek@...e.de>

This allows passing quotes in kernel arguments. It is useful for passing
nested arguemnts and might be useful if somebody wanted to pass a double
quote directly as part of an argument. It is also useful to have quoting
grammar more similar to shells and bootloaders.

Signed-off-by: Michal Suchanek <msuchanek@...e.de>
Signed-off-by: Hari Bathini <hbathini@...ux.vnet.ibm.com>
---
 lib/cmdline.c |   41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/lib/cmdline.c b/lib/cmdline.c
index 6d398a8..d98bdc0 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -193,30 +193,36 @@ bool parse_option_str(const char *str, const char *option)
 
 /*
  * 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)
 {
 	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)
+		if (isspace(args[i]) && !in_quote && !backslash)
 			break;
-		if (equals == 0) {
-			if (args[i] == '=')
-				equals = 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;
+
+				memmove(args + 1, args, i);
+				args++;
+				i--;
+			}
+		} else {
+			backslash = 0;
 		}
-		if (args[i] == '"')
-			in_quote = !in_quote;
 	}
 
 	*param = args;
@@ -225,13 +231,6 @@ char *next_arg(char *args, char **param, char **val)
 	else {
 		args[equals] = '\0';
 		*val = args + equals + 1;
-
-		/* Don't include quotes in value. */
-		if ((args[i-1] == '"') && ((quoted) || (**val == '"'))) {
-			args[i-1] = '\0';
-			if (!quoted)
-				(*val)++;
-		}
 	}
 
 	if (args[i]) {

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ