From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751424AbdIOROm (ORCPT ); Fri, 15 Sep 2017 13:14:42 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:38090 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750873AbdIOROl (ORCPT ); Fri, 15 Sep 2017 13:14:41 -0400 Date: Fri, 15 Sep 2017 18:14:09 +0100 From: Al Viro To: Michal Suchanek Cc: Jonathan Corbet , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Mauro Carvalho Chehab , Jani Nikula , Kamlakant Patel , Bamvor Jian Zhang , Tamara Diaconita , Trond Myklebust , Hari Bathini , Mahesh Salgaonkar , Andrew Morton , Nicholas Piggin , Baoquan He , Ilya Matveychikov , Ingo Molnar , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH 1/6] lib/cmdline.c: Add backslash support to kernel commandline parsing. Message-ID: <20170915171409.GZ5426@ZenIV.linux.org.uk> References: <4fabdf584ad18d6aae61e331f783a5020567f634.1505231820.git.msuchanek@suse.de> <28da60231eb848981e858fa33e3b7e33f8547111.1505494668.git.msuchanek@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <28da60231eb848981e858fa33e3b7e33f8547111.1505494668.git.msuchanek@suse.de> User-Agent: Mutt/1.8.3 (2017-05-23) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 15, 2017 at 07:02:46PM +0200, Michal Suchanek wrote: > 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.