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

* Re: [PATCH] cmd: nvedit: Validate argument count before use
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Vincent Stehlé @ 2025-12-18  8:21 UTC (permalink / raw)
  To: Marek Vasut
  Cc: u-boot, Heinrich Schuchardt, Ilias Apalodimas, Patrick Delaunay,
	Tom Rini

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@arm.com>

Best regards,
Vincent.

> 
> 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	[flat|nested] 4+ messages in thread

* Re: [PATCH] cmd: nvedit: Validate argument count before use
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Ilias Apalodimas @ 2025-12-18  9:30 UTC (permalink / raw)
  To: Marek Vasut
  Cc: u-boot, Heinrich Schuchardt, Patrick Delaunay, Tom Rini,
	Vincent Stehlé

On Wed, 17 Dec 2025 at 21:58, Marek Vasut
<marek.vasut+renesas@mailbox.org> 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"
>
> Fixes: a97d22ebba23 ("cmd: env: add env select command")
> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
> ---

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.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	[flat|nested] 4+ messages in thread

* Re: [PATCH] cmd: nvedit: Validate argument count before use
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2025-12-18 19:51 UTC (permalink / raw)
  To: u-boot, Marek Vasut
  Cc: Heinrich Schuchardt, Ilias Apalodimas, Vincent Stehlé,
	Patrick Delaunay

On Wed, 17 Dec 2025 20:57:38 +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"
> 
> [...]

Applied to u-boot/master, thanks!

[1/1] cmd: nvedit: Validate argument count before use
      commit: 2333d446b7b133ddfb9dea2d53996d560796ecd9
-- 
Tom



^ permalink raw reply	[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.