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 <[email protected]> --- 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
