Re: [PATCH 1/3] thermal: testing: Avoid NULL pointer dereference on missing arg
From: Guru Das Srinagesh
Date: Sat Jun 06 2026 - 23:00:13 EST
On Sun, Jun 07, 2026 at 12:04:18AM +0300, Ovidiu Panait wrote:
[...]
> To fix this, make arg an empty string instead of leaving it NULL when the
> separator is missing. sscanf() then fails correctly with -EINVAL on it.
[...]
> ---
> drivers/thermal/testing/command.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/thermal/testing/command.c b/drivers/thermal/testing/command.c
> index 1159ecea57e7..5513a26feed7 100644
> --- a/drivers/thermal/testing/command.c
> +++ b/drivers/thermal/testing/command.c
> @@ -150,6 +150,8 @@ static ssize_t tt_command_process(char *s)
> if (arg) {
> *arg = '\0';
> arg++;
> + } else {
> + arg = s + strlen(s);
> }
Here, `arg` is made to point to the NUL terminator of s. Couldn't this be simplified to:
arg = "";
to make the intent clearer? Since `tt_command_exec()` takes in arg as `const char *`,
pointing `arg` to a string literal is fine.