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


Groups > linux.kernel > #1714356 > unrolled thread

[PATCH v7 3/4] lib/cmdline.c Remove quotes symmetrically.

Started byMichal Suchanek <msuchanek@suse.de>
First post2017-08-17 22:20 +0200
Last post2017-08-24 14:20 +0200
Articles 6 — 5 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v7 3/4] lib/cmdline.c Remove quotes symmetrically. Michal Suchanek <msuchanek@suse.de> - 2017-08-17 22:20 +0200
    Re: [PATCH v7 3/4] lib/cmdline.c Remove quotes symmetrically. msuchanek <msuchanek@suse.de> - 2017-08-17 23:30 +0200
    Re: [PATCH v7 3/4] lib/cmdline.c Remove quotes symmetrically. Baoquan He <bhe@redhat.com> - 2017-08-21 12:30 +0200
      Re: [PATCH v7 3/4] lib/cmdline.c Remove quotes symmetrically. Michal Suchánek <msuchanek@suse.de> - 2017-08-21 13:40 +0200
    Re: [PATCH v7 3/4] lib/cmdline.c Remove quotes symmetrically. Michael Ellerman <mpe@ellerman.id.au> - 2017-08-24 13:10 +0200
      Re: [PATCH v7 3/4] lib/cmdline.c Remove quotes symmetrically. msuchanek <msuchanek@suse.de> - 2017-08-24 14:20 +0200

#1714356 — [PATCH v7 3/4] lib/cmdline.c Remove quotes symmetrically.

FromMichal Suchanek <msuchanek@suse.de>
Date2017-08-17 22:20 +0200
Subject[PATCH v7 3/4] lib/cmdline.c Remove quotes symmetrically.
Message-ID<ufzqN-1nj-9@gated-at.bofh.it>
Remove quotes from argument value only if there is qoute on both sides.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
 arch/powerpc/kernel/fadump.c | 6 ++----
 lib/cmdline.c                | 7 ++-----
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index a1614d9b8a21..d7da4ce9f7ae 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -489,10 +489,8 @@ static void __init fadump_update_params(struct param_info *param_info,
 	*tgt++ = ' ';
 
 	/* next_arg removes one leading and one trailing '"' */
-	if (*tgt == '"')
-		shortening += 1;
-	if (*(tgt + vallen + shortening) == '"')
-		shortening += 1;
+	if ((*tgt == '"') && (*(tgt + vallen + shortening) == '"'))
+		shortening += 2;
 
 	/* remove one leading and one trailing quote if both are present */
 	if ((val[0] == '"') && (val[vallen - 1] == '"')) {
diff --git a/lib/cmdline.c b/lib/cmdline.c
index 4c0888c4a68d..01e701b2afe8 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -227,14 +227,11 @@ char *next_arg(char *args, char **param, char **val)
 		*val = args + equals + 1;
 
 		/* Don't include quotes in value. */
-		if (**val == '"') {
+		if ((**val == '"') && (args[i-1] == '"')) {
 			(*val)++;
-			if (args[i-1] == '"')
-				args[i-1] = '\0';
+			args[i-1] = '\0';
 		}
 	}
-	if (quoted && args[i-1] == '"')
-		args[i-1] = '\0';
 
 	if (args[i]) {
 		args[i] = '\0';
-- 
2.10.2

[toc] | [next] | [standalone]


#1714393

Frommsuchanek <msuchanek@suse.de>
Date2017-08-17 23:30 +0200
Message-ID<ufAwB-26N-95@gated-at.bofh.it>
In reply to#1714356
On Thu, 17 Aug 2017 22:14:30 +0200
Michal Suchanek <msuchanek@suse.de> wrote:

> Remove quotes from argument value only if there is qoute on both
> sides.
> 
> Signed-off-by: Michal Suchanek <msuchanek@suse.de>
> ---
>  arch/powerpc/kernel/fadump.c | 6 ++----
>  lib/cmdline.c                | 7 ++-----
>  2 files changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/fadump.c
> b/arch/powerpc/kernel/fadump.c index a1614d9b8a21..d7da4ce9f7ae 100644
> --- a/arch/powerpc/kernel/fadump.c
> +++ b/arch/powerpc/kernel/fadump.c
> @@ -489,10 +489,8 @@ static void __init fadump_update_params(struct
> param_info *param_info, *tgt++ = ' ';
>  
>  	/* next_arg removes one leading and one trailing '"' */
> -	if (*tgt == '"')
> -		shortening += 1;
> -	if (*(tgt + vallen + shortening) == '"')
> -		shortening += 1;
> +	if ((*tgt == '"') && (*(tgt + vallen + shortening) == '"'))
s/shortening/1/                                ^

in case somebody would want this patch and not the following one that
removes the code.

[toc] | [prev] | [next] | [standalone]


#1716281

FromBaoquan He <bhe@redhat.com>
Date2017-08-21 12:30 +0200
Message-ID<ugS81-3aB-9@gated-at.bofh.it>
In reply to#1714356
On 08/17/17 at 10:14pm, Michal Suchanek wrote:
> Remove quotes from argument value only if there is qoute on both sides.
> 
> Signed-off-by: Michal Suchanek <msuchanek@suse.de>

Sounds reasonable. Just for curiosity, do we have chance to pass in
option with a single '"'?

> ---
>  arch/powerpc/kernel/fadump.c | 6 ++----
>  lib/cmdline.c                | 7 ++-----
>  2 files changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
> index a1614d9b8a21..d7da4ce9f7ae 100644
> --- a/arch/powerpc/kernel/fadump.c
> +++ b/arch/powerpc/kernel/fadump.c
> @@ -489,10 +489,8 @@ static void __init fadump_update_params(struct param_info *param_info,
>  	*tgt++ = ' ';
>  
>  	/* next_arg removes one leading and one trailing '"' */
> -	if (*tgt == '"')
> -		shortening += 1;
> -	if (*(tgt + vallen + shortening) == '"')
> -		shortening += 1;
> +	if ((*tgt == '"') && (*(tgt + vallen + shortening) == '"'))
> +		shortening += 2;
>  
>  	/* remove one leading and one trailing quote if both are present */
>  	if ((val[0] == '"') && (val[vallen - 1] == '"')) {
> diff --git a/lib/cmdline.c b/lib/cmdline.c
> index 4c0888c4a68d..01e701b2afe8 100644
> --- a/lib/cmdline.c
> +++ b/lib/cmdline.c
> @@ -227,14 +227,11 @@ char *next_arg(char *args, char **param, char **val)
>  		*val = args + equals + 1;
>  
>  		/* Don't include quotes in value. */
> -		if (**val == '"') {
> +		if ((**val == '"') && (args[i-1] == '"')) {
>  			(*val)++;
> -			if (args[i-1] == '"')
> -				args[i-1] = '\0';
> +			args[i-1] = '\0';
>  		}
>  	}
> -	if (quoted && args[i-1] == '"')
> -		args[i-1] = '\0';
>  
>  	if (args[i]) {
>  		args[i] = '\0';
> -- 
> 2.10.2
> 

[toc] | [prev] | [next] | [standalone]


#1716352

FromMichal Suchánek <msuchanek@suse.de>
Date2017-08-21 13:40 +0200
Message-ID<ugTdM-3NW-23@gated-at.bofh.it>
In reply to#1716281
On Mon, 21 Aug 2017 18:27:12 +0800
Baoquan He <bhe@redhat.com> wrote:

> On 08/17/17 at 10:14pm, Michal Suchanek wrote:
> > Remove quotes from argument value only if there is qoute on both
> > sides.
> > 
> > Signed-off-by: Michal Suchanek <msuchanek@suse.de>  
> 
> Sounds reasonable. Just for curiosity, do we have chance to pass in
> option with a single '"'?

No, we don't. Perhaps it would work if it was at the end of the
commandline.

next_arg checks that quoting is closed.

It was possible but undocumented with previous behavior - you would
place the quote in the middle and the closing quote at start or end so
that next_arg would remove the closing quote but not the one in the
middle.

It would be also possible with shell-like backslash escaping but that
is not implemented.

Thanks

Michal

[toc] | [prev] | [next] | [standalone]


#1719158

FromMichael Ellerman <mpe@ellerman.id.au>
Date2017-08-24 13:10 +0200
Message-ID<uhYbn-5DS-5@gated-at.bofh.it>
In reply to#1714356
Michal Suchanek <msuchanek@suse.de> writes:

> Remove quotes from argument value only if there is qoute on both sides.
>
> Signed-off-by: Michal Suchanek <msuchanek@suse.de>
> ---
>  arch/powerpc/kernel/fadump.c | 6 ++----
>  lib/cmdline.c                | 7 ++-----

Can you split that into two patches?

cheers

>  2 files changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
> index a1614d9b8a21..d7da4ce9f7ae 100644
> --- a/arch/powerpc/kernel/fadump.c
> +++ b/arch/powerpc/kernel/fadump.c
> @@ -489,10 +489,8 @@ static void __init fadump_update_params(struct param_info *param_info,
>  	*tgt++ = ' ';
>  
>  	/* next_arg removes one leading and one trailing '"' */
> -	if (*tgt == '"')
> -		shortening += 1;
> -	if (*(tgt + vallen + shortening) == '"')
> -		shortening += 1;
> +	if ((*tgt == '"') && (*(tgt + vallen + shortening) == '"'))
> +		shortening += 2;
>  
>  	/* remove one leading and one trailing quote if both are present */
>  	if ((val[0] == '"') && (val[vallen - 1] == '"')) {
> diff --git a/lib/cmdline.c b/lib/cmdline.c
> index 4c0888c4a68d..01e701b2afe8 100644
> --- a/lib/cmdline.c
> +++ b/lib/cmdline.c
> @@ -227,14 +227,11 @@ char *next_arg(char *args, char **param, char **val)
>  		*val = args + equals + 1;
>  
>  		/* Don't include quotes in value. */
> -		if (**val == '"') {
> +		if ((**val == '"') && (args[i-1] == '"')) {
>  			(*val)++;
> -			if (args[i-1] == '"')
> -				args[i-1] = '\0';
> +			args[i-1] = '\0';
>  		}
>  	}
> -	if (quoted && args[i-1] == '"')
> -		args[i-1] = '\0';
>  
>  	if (args[i]) {
>  		args[i] = '\0';
> -- 
> 2.10.2

[toc] | [prev] | [next] | [standalone]


#1719187

Frommsuchanek <msuchanek@suse.de>
Date2017-08-24 14:20 +0200
Message-ID<uhZh7-6r5-9@gated-at.bofh.it>
In reply to#1719158
On Thu, 24 Aug 2017 21:02:47 +1000
Michael Ellerman <mpe@ellerman.id.au> wrote:

> Michal Suchanek <msuchanek@suse.de> writes:
> 
> > Remove quotes from argument value only if there is qoute on both
> > sides.
> >
> > Signed-off-by: Michal Suchanek <msuchanek@suse.de>
> > ---
> >  arch/powerpc/kernel/fadump.c | 6 ++----
> >  lib/cmdline.c                | 7 ++-----  
> 
> Can you split that into two patches?

Not really. There is logic in lib/cmdline.c which is duplicated in
arch/powerpc/kernel/fadump.c and so the two places should be updated in
sync. 

Thanks

Michal

> 
> cheers
> 
> >  2 files changed, 4 insertions(+), 9 deletions(-)
> >
> > diff --git a/arch/powerpc/kernel/fadump.c
> > b/arch/powerpc/kernel/fadump.c index a1614d9b8a21..d7da4ce9f7ae
> > 100644 --- a/arch/powerpc/kernel/fadump.c
> > +++ b/arch/powerpc/kernel/fadump.c
> > @@ -489,10 +489,8 @@ static void __init fadump_update_params(struct
> > param_info *param_info, *tgt++ = ' ';
> >  
> >  	/* next_arg removes one leading and one trailing '"' */
> > -	if (*tgt == '"')
> > -		shortening += 1;
> > -	if (*(tgt + vallen + shortening) == '"')
> > -		shortening += 1;
> > +	if ((*tgt == '"') && (*(tgt + vallen + shortening) == '"'))
> > +		shortening += 2;
> >  
> >  	/* remove one leading and one trailing quote if both are
> > present */ if ((val[0] == '"') && (val[vallen - 1] == '"')) {
> > diff --git a/lib/cmdline.c b/lib/cmdline.c
> > index 4c0888c4a68d..01e701b2afe8 100644
> > --- a/lib/cmdline.c
> > +++ b/lib/cmdline.c
> > @@ -227,14 +227,11 @@ char *next_arg(char *args, char **param, char
> > **val) *val = args + equals + 1;
> >  
> >  		/* Don't include quotes in value. */
> > -		if (**val == '"') {
> > +		if ((**val == '"') && (args[i-1] == '"')) {
> >  			(*val)++;
> > -			if (args[i-1] == '"')
> > -				args[i-1] = '\0';
> > +			args[i-1] = '\0';
> >  		}
> >  	}
> > -	if (quoted && args[i-1] == '"')
> > -		args[i-1] = '\0';
> >  
> >  	if (args[i]) {
> >  		args[i] = '\0';
> > -- 
> > 2.10.2  

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web