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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

> On Fri, 15 Sep 2017 18:14:09 +0100
> Al Viro <viro@xxxxxxxxxxxxxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux