lkml.org 
[lkml]   [2015]   [Dec]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v3 2/8] lib: add "on" and "off" to strtobool
From
On Wed, Dec 9, 2015 at 11:43 PM, Kees Cook <keescook@chromium.org> wrote:
> Several places in the kernel expect to use "on" and "off" for their
> boolean signifiers, so add them to strtobool.
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> ---
> lib/string.c | 21 ++++++++++++++++++++-
> 1 file changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/lib/string.c b/lib/string.c
> index 0323c0d5629a..d7550432f91c 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -635,12 +635,16 @@ EXPORT_SYMBOL(sysfs_streq);
> * @s: input string
> * @res: result
> *
> - * This routine returns 0 iff the first character is one of 'Yy1Nn0'.
> + * This routine returns 0 iff the first character is one of 'Yy1Nn0', or
> + * 'Oo' when the second character is one of 'fFnN' (for "on" and "off").

Maybe

…or [Oo][FfNn] for "off" and "on"…


> * Otherwise it will return -EINVAL. Value pointed to by res is
> * updated upon finding a match.
> */
> int strtobool(const char *s, bool *res)
> {

> + if (!s)
> + return -EINVAL;
> +

This change I think is better to do separately. Do we have even need for it?

> switch (s[0]) {
> case 'y':
> case 'Y':
> @@ -652,6 +656,21 @@ int strtobool(const char *s, bool *res)
> case '0':
> *res = false;
> break;
> + case 'o':
> + case 'O':
> + switch (s[1]) {
> + case 'n':
> + case 'N':
> + *res = true;
> + break;
> + case 'f':
> + case 'F':
> + *res = false;
> + break;


> + default:
> + return -EINVAL;
> + }
> + break;
> default:
> return -EINVAL;

Maybe in both cases
default:
break;
}

}
return -EINVAL;

--
With Best Regards,
Andy Shevchenko


\
 
 \ /
  Last update: 2015-12-11 18:21    [W:0.058 / U:0.356 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site