From: Marek Vasut Date: Wed, 17 Dec 2025 19:57:38 +0000 (+0100) Subject: cmd: nvedit: Validate argument count before use X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2333d446b7b133ddfb9dea2d53996d560796ecd9;p=thirdparty%2Fu-boot.git cmd: nvedit: Validate argument count before use 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" Fixes: a97d22ebba23 ("cmd: env: add env select command") Signed-off-by: Marek Vasut Tested-by: Vincent Stehlé Reviewed-by: Ilias Apalodimas --- 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