Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1739213

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

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From Michal Suchánek <msuchanek@suse.de>
Newsgroups linux.kernel
Subject Re: [PATCH 1/6] lib/cmdline.c: Add backslash support to kernel commandline parsing.
Date Mon, 25 Sep 2017 20:50:01 +0200
Message-ID <utGC5-1Kz-1@gated-at.bofh.it> (permalink)
References <uoVV8-3tT-21@gated-at.bofh.it> <uq2hP-5TN-3@gated-at.bofh.it> <uq2rv-5Xm-3@gated-at.bofh.it> <uq2Bb-61b-11@gated-at.bofh.it>
X-Mailer Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-suse-linux-gnu)
MIME-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8BIT
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 53
Organization linux.* mail to news gateway
X-Original-Cc Tamara Diaconita <diaconitatamara@gmail.com>, Baoquan He <bhe@redhat.com>, Kamlakant Patel <kamlakant.patel@broadcom.com>, Jonathan Corbet <corbet@lwn.net>, Jani Nikula <jani.nikula@intel.com>, Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>, Trond Myklebust <trond.myklebust@primarydata.com>, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Nicholas Piggin <npiggin@gmail.com>, Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>, Andrew Morton <akpm@linux-foundation.org>, Paul Mackerras <paulus@samba.org>, Hari Bathini <hbathini@linux.vnet.ibm.com>, Ilya Matveychikov <matvejchikov@gmail.com>, Mauro Carvalho Chehab <mchehab@kernel.org>, linuxppc-dev@lists.ozlabs.org, Ingo Molnar <mingo@kernel.org>
X-Original-Date Mon, 25 Sep 2017 20:39:01 +0200
X-Original-Message-ID <20170925203901.0009b327@naga>
X-Original-References <4fabdf584ad18d6aae61e331f783a5020567f634.1505231820.git.msuchanek@suse.de> <28da60231eb848981e858fa33e3b7e33f8547111.1505494668.git.msuchanek@suse.de> <20170915171409.GZ5426@ZenIV.linux.org.uk> <20170915192856.1d5708b6@kitsune.suse.cz>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1739213

Show key headers only | View raw


On Fri, 15 Sep 2017 19:28:56 +0200
Michal Suchánek <msuchanek@suse.de> wrote:

> On Fri, 15 Sep 2017 18:14:09 +0100
> Al Viro <viro@ZenIV.linux.org.uk> wrote:
> 
> > 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.  
> 
> Care to share how it is broken?

Guess not. I will assume it is perfectly fine then. It works perfectly
fine in my testing.

Using memmove for string rewrite is not a matter of taste. It is the
only library function with sane semantics for rewrite of anything. Then
again open-coding it is always an option and maybe in better taste for
some :->

Michal

Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

[PATCH v8 6/6] powerpc/fadump: use the new parse_args callback arguments Michal Suchanek <msuchanek@suse.de> - 2017-09-12 18:10 +0200
  [PATCH 1/6] lib/cmdline.c: Add backslash support to kernel commandline parsing. Michal Suchanek <msuchanek@suse.de> - 2017-09-15 19:10 +0200
    Re: [PATCH 1/6] lib/cmdline.c: Add backslash support to kernel  commandline parsing. Al Viro <viro@ZenIV.linux.org.uk> - 2017-09-15 19:20 +0200
      Re: [PATCH 1/6] lib/cmdline.c: Add backslash support to kernel  commandline parsing. Michal Suchánek <msuchanek@suse.de> - 2017-09-15 19:30 +0200
        Re: [PATCH 1/6] lib/cmdline.c: Add backslash support to kernel  commandline parsing. Michal Suchánek <msuchanek@suse.de> - 2017-09-25 20:50 +0200

csiph-web