Re: [PATCH] printk: handle blank console arguments passed in.

From: Sergey Senozhatsky
Date: Tue Mar 17 2020 - 04:22:44 EST


On (20/03/16 19:17), Shreyas Joshi wrote:
>
> Thanks! I thought If we put a warning there then it wonât print anything.
> Please advise. I will send a new patch with the line wrapping to at most 75 once
> I know if I need to change anything more.
>

What I'm thinking about is turning "param=\0" into invalid case,
not just for printk(), for in general. Treat it as a NULL value.

Something like this, perhaps?

---
init/main.c | 4 ++++
lib/cmdline.c | 8 ++++++--
2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/init/main.c b/init/main.c
index d46b5673ecb4..46b732cd2615 100644
--- a/init/main.c
+++ b/init/main.c
@@ -673,6 +673,10 @@ static int __init do_early_param(char *param, char *val,
(strcmp(param, "console") == 0 &&
strcmp(p->str, "earlycon") == 0)
) {
+ if (!val && strchr(p->str, '=')) {
+ pr_warn("Malformed early option '%s'\n", param);
+ continue;
+ }
if (p->setup_func(val) != 0)
pr_warn("Malformed early option '%s'\n", param);
}
diff --git a/lib/cmdline.c b/lib/cmdline.c
index fbb9981a04a4..33fa0fc505a0 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -222,9 +222,9 @@ char *next_arg(char *args, char **param, char **val)
}

*param = args;
- if (!equals)
+ if (!equals) {
*val = NULL;
- else {
+ } else {
args[equals] = '\0';
*val = args + equals + 1;

@@ -244,6 +244,10 @@ char *next_arg(char *args, char **param, char **val)
} else
next = args + i;

+ /* Treat blank param value, e.g. 'param=', as NULL value. */
+ if (equals && **val == '\0')
+ *val = NULL;
+
/* Chew up trailing spaces. */
return skip_spaces(next);
}
--
2.25.1.481.gfbce0eb801-goog