mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] param: return error when assigning empty string
@ 2026-05-07 11:49 Ahmad Fatoum
  2026-05-11  7:15 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2026-05-07 11:49 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The fallback path that allows specifying enum values by index returns an
error if *endp != '\0' to account for invalid values like my.enum.param=1z.

This fails to account for the corner case of the empty string which
would also have *endp == '\0; with idx being the default 0.

Check for that explicitly and return an error.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 lib/parameter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/parameter.c b/lib/parameter.c
index f4e62cc1ae87..e98739725fe2 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -593,7 +593,7 @@ static int param_enum_set(struct bobject *bobj, struct param_d *p,
 		char *endp;
 		unsigned long idx = simple_strtoul(val, &endp, 0);
 
-		if (*endp || idx >= pe->num_names || !pe->names[idx])
+		if (*endp || endp == val || idx >= pe->num_names || !pe->names[idx])
 			return -EINVAL;
 
 		pr_warn("setting %s.%s by index is not stable, use \"%s\" instead\n",
-- 
2.47.3




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

* Re: [PATCH] param: return error when assigning empty string
  2026-05-07 11:49 [PATCH] param: return error when assigning empty string Ahmad Fatoum
@ 2026-05-11  7:15 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2026-05-11  7:15 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Thu, 07 May 2026 13:49:18 +0200, Ahmad Fatoum wrote:
> The fallback path that allows specifying enum values by index returns an
> error if *endp != '\0' to account for invalid values like my.enum.param=1z.
> 
> This fails to account for the corner case of the empty string which
> would also have *endp == '\0; with idx being the default 0.
> 
> Check for that explicitly and return an error.
> 
> [...]

Applied, thanks!

[1/1] param: return error when assigning empty string
      https://git.pengutronix.de/cgit/barebox/commit/?id=fb0edacd3624 (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:[~2026-05-11  7:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-07 11:49 [PATCH] param: return error when assigning empty string Ahmad Fatoum
2026-05-11  7:15 ` Sascha Hauer

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