[PATCH] cmd: nvedit: Validate argument count before use
Vincent Stehlé
vincent.stehle at arm.com
Thu Dec 18 09:21:07 CET 2025
On Wed, Dec 17, 2025 at 08:57:38PM +0100, Marek Vasut wrote:
> Avoid NULL pointer dereference in case 'env select' is invoked
> without parameters, check the arg count and make sure it is at
> least 2, otherwise print usage.
>
> The crash is easy to trigger e.g. in sandbox:
> $ ./u-boot -Tc "env select"
Thanks Marek.
I confirm this patch does indeed fix the crash on sandbox.
The behaviour remains the same when selecting "nowhere".
Feel free to add (or not):
Tested-by: Vincent Stehlé <vincent.stehle at arm.com>
Best regards,
Vincent.
>
> Fixes: a97d22ebba23 ("cmd: env: add env select command")
> Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
> ---
> Cc: Heinrich Schuchardt <xypron.glpk at gmx.de>
> Cc: Ilias Apalodimas <ilias.apalodimas at linaro.org>
> Cc: Patrick Delaunay <patrick.delaunay at st.com>
> Cc: Tom Rini <trini at konsulko.com>
> Cc: Vincent Stehlé <vincent.stehle at arm.com>
> Cc: u-boot at lists.denx.de
> ---
> cmd/nvedit.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/cmd/nvedit.c b/cmd/nvedit.c
> index 11c3cea882b..636bddee1be 100644
> --- a/cmd/nvedit.c
> +++ b/cmd/nvedit.c
> @@ -499,6 +499,9 @@ static int do_env_load(struct cmd_tbl *cmdtp, int flag, int argc,
> static int do_env_select(struct cmd_tbl *cmdtp, int flag, int argc,
> char *const argv[])
> {
> + if (argc < 2)
> + return CMD_RET_USAGE;
> +
> return env_select(argv[1]) ? 1 : 0;
> }
> #endif
> --
> 2.51.0
>
More information about the U-Boot
mailing list