linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Hari Bathini <hbathini@linux.vnet.ibm.com>
To: linuxppc-dev <linuxppc-dev@ozlabs.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	lkml <linux-kernel@vger.kernel.org>
Cc: "Michael Ellerman" <mpe@ellerman.id.au>,
	"Ankit Kumar" <ankit@linux.vnet.ibm.com>,
	"Michal Suchánek" <msuchanek@suse.de>,
	"Mahesh J Salgaonkar" <mahesh@linux.vnet.ibm.com>
Subject: [PATCH v9 5/8] lib/cmdline.c: implement single quotes in commandline argument parsing
Date: Wed, 15 Nov 2017 20:48:25 +0530	[thread overview]
Message-ID: <151075906562.14434.17655499193254963975.stgit@hbathini.in.ibm.com> (raw)
In-Reply-To: <151075897205.14434.9005256552409420263.stgit@hbathini.in.ibm.com>

From: Michal Suchanek <msuchanek@suse.de>

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@suse.de>
---
 lib/cmdline.c |   29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/lib/cmdline.c b/lib/cmdline.c
index d98bdc0..c5335a7 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -191,34 +191,45 @@ bool parse_option_str(const char *str, const char *option)
 	return false;
 }
 
+#define squash_char { \
+	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)
 {
 	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++) {
-		if (isspace(args[i]) && !in_quote && !backslash)
+		if (isspace(args[i]) && !in_quote && !backslash && !in_single)
 			break;
 
 		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;
-
-				memmove(args + 1, args, i);
-				args++;
-				i--;
+				if (args[i] == '\'')
+					in_single = 1;
+				squash_char;
 			}
 		} else {
 			backslash = 0;

  parent reply	other threads:[~2017-11-15 15:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-15 15:16 [PATCH v9 0/8] reduce memory consumption for powerpc firmware-assisted capture kernel Hari Bathini
2017-11-15 15:16 ` [PATCH v9 1/8] lib/cmdline.c: remove quotes symmetrically Hari Bathini
2017-12-15 20:51   ` Michal Suchánek
2017-11-15 15:17 ` [PATCH v9 2/8] boot/param: add pointer to current and next argument to unknown parameter callback Hari Bathini
2017-12-15 20:47   ` Michal Suchánek
2017-12-15 21:41     ` [PATCH] Fix parse_args cycle limit check Michal Suchanek
2017-12-15 23:49       ` Randy Dunlap
2017-12-18 17:34         ` Michal Suchánek
2017-12-18 17:57           ` Randy Dunlap
2017-11-15 15:17 ` [PATCH v9 3/8] lib/cmdline.c: add backslash support to kernel commandline parsing Hari Bathini
2017-11-15 15:17 ` [PATCH v9 4/8] Documentation/admin-guide: backslash support in commandline Hari Bathini
2017-11-15 15:18 ` Hari Bathini [this message]
2017-12-15 21:49   ` [PATCH] Optimize final quote removal Michal Suchanek
2017-11-15 15:18 ` [PATCH v9 6/8] Documentation/admin-guide: single quotes in kernel arguments Hari Bathini
2017-11-15 15:19 ` [PATCH v9 7/8] powerpc/fadump: reduce memory consumption for capture kernel Hari Bathini
2017-11-15 15:19 ` [PATCH v9 8/8] powerpc/fadump: update documentation about 'fadump_extra_args=' parameter Hari Bathini
2022-03-11 17:02 ` [PATCH v9 0/8] reduce memory consumption for powerpc firmware-assisted capture kernel Christophe Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=151075906562.14434.17655499193254963975.stgit@hbathini.in.ibm.com \
    --to=hbathini@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=ankit@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=mahesh@linux.vnet.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=msuchanek@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).