* [PATCH] param: return error when assigning empty string
@ 2026-05-07 11:49 Ahmad Fatoum
0 siblings, 0 replies; only message 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] only message in thread
only message in thread, other threads:[~2026-05-07 11:50 UTC | newest]
Thread overview: (only message) (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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox