mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fixup! bootchooser: implement locking of attempts counter
@ 2025-06-23 13:13 Ahmad Fatoum
  2025-06-24  7:19 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-06-23 13:13 UTC (permalink / raw)
  To: barebox; +Cc: Lars Schmidt, Ahmad Fatoum

We have two code paths with goto err that don't set ret beforehand with
the expectation that the default -EINVAL will be used.

ret is now being reused though and thus the -EINVAL is clobbered. In the
worst case, an error ends up with ERR_PTR(ret) == NULL crashing
bootchooser -i when a state prefix is set, but no targets are defined.

Fix this by always initializing ret explicitly.

Cc: Lars Schmidt <l.schmidt@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/bootchooser.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/bootchooser.c b/common/bootchooser.c
index 623cb8ce7714..a79eee8ca2c4 100644
--- a/common/bootchooser.c
+++ b/common/bootchooser.c
@@ -352,7 +352,7 @@ struct bootchooser *bootchooser_get(void)
 	struct bootchooser *bc;
 	struct bootchooser_target *target;
 	char *targets, *str, *freep = NULL, *delim;
-	int ret = -EINVAL, id = 1;
+	int ret, id = 1;
 	uint32_t last_chosen;
 	static int attempts_resetted;
 	uint32_t locked;
@@ -430,11 +430,13 @@ struct bootchooser *bootchooser_get(void)
 
 	if (id == 1) {
 		pr_err("Target list $global.bootchooser.targets is empty\n");
+		ret = -EINVAL;
 		goto err;
 	}
 
 	if (list_empty(&bc->targets)) {
 		pr_err("No targets could be initialized\n");
+		ret = -EINVAL;
 		goto err;
 	}
 
-- 
2.39.5




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

* Re: [PATCH] fixup! bootchooser: implement locking of attempts counter
  2025-06-23 13:13 [PATCH] fixup! bootchooser: implement locking of attempts counter Ahmad Fatoum
@ 2025-06-24  7:19 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2025-06-24  7:19 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum; +Cc: Lars Schmidt


On Mon, 23 Jun 2025 15:13:06 +0200, Ahmad Fatoum wrote:
> We have two code paths with goto err that don't set ret beforehand with
> the expectation that the default -EINVAL will be used.
> 
> ret is now being reused though and thus the -EINVAL is clobbered. In the
> worst case, an error ends up with ERR_PTR(ret) == NULL crashing
> bootchooser -i when a state prefix is set, but no targets are defined.
> 
> [...]

Applied, thanks!

[1/1] fixup! bootchooser: implement locking of attempts counter
      https://git.pengutronix.de/cgit/barebox/commit/?id=77bd8dac6962 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2025-06-24  7:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-23 13:13 [PATCH] fixup! bootchooser: implement locking of attempts counter Ahmad Fatoum
2025-06-24  7:19 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox