2017-12-15 21:33:28

by Michal Suchánek

[permalink] [raw]
Subject: [PATCH] init/main.c: simplify repair_env_string

Quoting characters are now removed from the parameter so value always
follows directly after the NUL terminating parameter name.

Signed-off-by: Michal Suchanek <[email protected]>
---
init/main.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)

Since the previous "[PATCH v9 3/8] lib/cmdline.c: add backslash support to
kernel commandline parsing" adds the memmove in lib/cmdline.c it is now
superfluous in init/main.c

diff --git a/init/main.c b/init/main.c
index 1f5fdedbb293..1e5b1dc940d9 100644
--- a/init/main.c
+++ b/init/main.c
@@ -244,15 +244,10 @@ static int __init repair_env_string(char *param, char *val,
const char *unused, void *arg)
{
if (val) {
- /* param=val or param="val"? */
- if (val == param+strlen(param)+1)
- val[-1] = '=';
- else if (val == param+strlen(param)+2) {
- val[-2] = '=';
- memmove(val-1, val, strlen(val)+1);
- val--;
- } else
- BUG();
+ int parm_len = strlen(param);
+
+ param[parm_len] = '=';
+ BUG_ON(val != param + parm_len + 1);
}
return 0;
}
--
2.13.6


2018-05-04 15:42:27

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] init/main.c: simplify repair_env_string


Cleaning out my INBOX, I stumbled across this old patch.

On Fri, 15 Dec 2017 22:33:17 +0100
Michal Suchanek <[email protected]> wrote:

> Quoting characters are now removed from the parameter so value always
> follows directly after the NUL terminating parameter name.
>
> Signed-off-by: Michal Suchanek <[email protected]>
> ---
> init/main.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> Since the previous "[PATCH v9 3/8] lib/cmdline.c: add backslash support to
> kernel commandline parsing" adds the memmove in lib/cmdline.c it is now
> superfluous in init/main.c

I don't believe the above patches were ever applied. Were they?

-- Steve

>
> diff --git a/init/main.c b/init/main.c
> index 1f5fdedbb293..1e5b1dc940d9 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -244,15 +244,10 @@ static int __init repair_env_string(char *param, char *val,
> const char *unused, void *arg)
> {
> if (val) {
> - /* param=val or param="val"? */
> - if (val == param+strlen(param)+1)
> - val[-1] = '=';
> - else if (val == param+strlen(param)+2) {
> - val[-2] = '=';
> - memmove(val-1, val, strlen(val)+1);
> - val--;
> - } else
> - BUG();
> + int parm_len = strlen(param);
> +
> + param[parm_len] = '=';
> + BUG_ON(val != param + parm_len + 1);
> }
> return 0;
> }


2018-05-04 16:09:31

by Michal Suchánek

[permalink] [raw]
Subject: Re: [PATCH] init/main.c: simplify repair_env_string

On Fri, 4 May 2018 11:40:35 -0400
Steven Rostedt <[email protected]> wrote:

> Cleaning out my INBOX, I stumbled across this old patch.
>
> On Fri, 15 Dec 2017 22:33:17 +0100
> Michal Suchanek <[email protected]> wrote:
>
> > Quoting characters are now removed from the parameter so value
> > always follows directly after the NUL terminating parameter name.
> >
> > Signed-off-by: Michal Suchanek <[email protected]>
> > ---
> > init/main.c | 13 ++++---------
> > 1 file changed, 4 insertions(+), 9 deletions(-)
> >
> > Since the previous "[PATCH v9 3/8] lib/cmdline.c: add backslash
> > support to kernel commandline parsing" adds the memmove in
> > lib/cmdline.c it is now superfluous in init/main.c
>
> I don't believe the above patches were ever applied. Were they?

No, they weren't.

The reason to write them was to support the fadump_extra_args argument
with peculiar semantics that required the quoting cleanup in kernel
argument parsing.

A different solution for the fadump memory consumption is in the works
so I dropped this. There was lack of interest from reviewers, too.

Thanks

Michal

>
> -- Steve
>
> >
> > diff --git a/init/main.c b/init/main.c
> > index 1f5fdedbb293..1e5b1dc940d9 100644
> > --- a/init/main.c
> > +++ b/init/main.c
> > @@ -244,15 +244,10 @@ static int __init repair_env_string(char
> > *param, char *val, const char *unused, void *arg)
> > {
> > if (val) {
> > - /* param=val or param="val"? */
> > - if (val == param+strlen(param)+1)
> > - val[-1] = '=';
> > - else if (val == param+strlen(param)+2) {
> > - val[-2] = '=';
> > - memmove(val-1, val, strlen(val)+1);
> > - val--;
> > - } else
> > - BUG();
> > + int parm_len = strlen(param);
> > +
> > + param[parm_len] = '=';
> > + BUG_ON(val != param + parm_len + 1);
> > }
> > return 0;
> > }
>