Thread (20 messages) flat view 20 messages, 4 authors, 2017-09-29

Re: [PATCH 1/6] lib/cmdline.c: Add backslash support to kernel commandline parsing.

From: Michal Suchánek <hidden>
Date: 2017-09-15 17:29:01
Also in: lkml

On Fri, 15 Sep 2017 18:14:09 +0100
Al Viro [off-list ref] wrote:
On Fri, Sep 15, 2017 at 07:02:46PM +0200, Michal Suchanek wrote:
quoted
 	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;
 	}  
... and that makes for Unidiomatic Work With Strings Award for this
September. Using memmove() for string rewrite is almost always bad
taste; in this case it's also (as usual) broken.
Care to share how it is broken?

Thanks

Michal
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help