All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cmd: nvedit: Validate argument count before use
@ 2025-12-17 19:57 Marek Vasut
  2025-12-18  8:21 ` Vincent Stehlé
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Marek Vasut @ 2025-12-17 19:57 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Heinrich Schuchardt, Ilias Apalodimas,
	Patrick Delaunay, Tom Rini, Vincent Stehlé

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>
---
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Cc: Tom Rini <trini@konsulko.com>
Cc: Vincent Stehlé <vincent.stehle@arm.com>
Cc: u-boot@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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-12-18 19:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-17 19:57 [PATCH] cmd: nvedit: Validate argument count before use Marek Vasut
2025-12-18  8:21 ` Vincent Stehlé
2025-12-18  9:30 ` Ilias Apalodimas
2025-12-18 19:51 ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.