[PATCH] common/command.c: Avoid NULL pointer use in cmd_auto_complete
Simon Glass
sjg at chromium.org
Fri May 15 15:58:38 CEST 2026
Hi Adam,
On 2026-05-14T14:06:41, Adam Lackorzynski <adam at l4re.org> wrote:
> common/command.c: Avoid NULL pointer use in cmd_auto_complete
>
> Avoid putting a potential NULL pointer to strcmp, which would lead to a
> load at address 0.
>
> Signed-off-by: Adam Lackorzynski <adam at l4re.org>
>
> common/command.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> diff --git a/common/command.c b/common/command.c
> @@ -373,7 +373,7 @@ int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
> const char *ps_prompt = CONFIG_SYS_PROMPT;
> #endif
>
> - if (strcmp(prompt, ps_prompt) != 0)
> + if (ps_prompt && strcmp(prompt, ps_prompt) != 0)
> return 0; /* not in normal console */
This avoids the deref but isn't quite right. uboot_cli_readline() in
common/cli_hush.c falls back to CONFIG_SYS_PROMPT (or
CONFIG_SYS_PROMPT_HUSH_PS2 for promptmode 2) when PS1 is unset, so
prompt here is never NULL. With your change, a NULL PS1 makes the
comparison succeed unconditionally and promptmode 2 gets treated as
the normal console.
Please can you fall back to the default when env_get() returns NULL,
mirroring the readline path:
const char *ps_prompt;
if (IS_ENABLED(CONFIG_CMDLINE_PS_SUPPORT)) {
ps_prompt = env_get('PS1');
if (!ps_prompt)
ps_prompt = CONFIG_SYS_PROMPT;
} else {
ps_prompt = CONFIG_SYS_PROMPT;
}
What do you think?
Regards,
Simon
More information about the U-Boot
mailing list