]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
cmd: nvedit: Validate argument count before use
authorMarek Vasut <marek.vasut+renesas@mailbox.org>
Wed, 17 Dec 2025 19:57:38 +0000 (20:57 +0100)
committerTom Rini <trini@konsulko.com>
Thu, 18 Dec 2025 16:26:22 +0000 (10:26 -0600)
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 <marek.vasut+renesas@mailbox.org>
Tested-by: Vincent Stehlé <vincent.stehle@arm.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
cmd/nvedit.c

index 11c3cea882b86e69be89edc8e81d5e8689a3c90c..636bddee1bea2f5e225a48b67d1e9898c1ab0d5a 100644 (file)
@@ -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