From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kees Cook Subject: [PATCH v3 2/8] lib: add "on" and "off" to strtobool Date: Wed, 9 Dec 2015 13:43:18 -0800 Message-ID: <1449697404-21076-3-git-send-email-keescook@chromium.org> References: <1449697404-21076-1-git-send-email-keescook@chromium.org> Return-path: In-Reply-To: <1449697404-21076-1-git-send-email-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org To: linux-kernel@vger.kernel.org Cc: Kees Cook , Rasmus Villemoes , Daniel Borkmann , Ingo Molnar , Andy Lutomirski , "H. Peter Anvin" , Michael Ellerman , Mathias Krause , Thomas Gleixner , x86@kernel.org, Arnd Bergmann , PaX Team , Emese Revfy , kernel-hardening@lists.openwall.com, linux-arch List-Id: linux-arch.vger.kernel.org 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 Cc: Rasmus Villemoes Cc: Daniel Borkmann --- 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"). * 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; + 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; } -- 1.9.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.outflux.net ([198.145.64.163]:39524 "EHLO smtp.outflux.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753705AbbLIVoc (ORCPT ); Wed, 9 Dec 2015 16:44:32 -0500 From: Kees Cook Subject: [PATCH v3 2/8] lib: add "on" and "off" to strtobool Date: Wed, 9 Dec 2015 13:43:18 -0800 Message-ID: <1449697404-21076-3-git-send-email-keescook@chromium.org> In-Reply-To: <1449697404-21076-1-git-send-email-keescook@chromium.org> References: <1449697404-21076-1-git-send-email-keescook@chromium.org> Sender: linux-arch-owner@vger.kernel.org List-ID: To: linux-kernel@vger.kernel.org Cc: Kees Cook , Rasmus Villemoes , Daniel Borkmann , Ingo Molnar , Andy Lutomirski , "H. Peter Anvin" , Michael Ellerman , Mathias Krause , Thomas Gleixner , x86@kernel.org, Arnd Bergmann , PaX Team , Emese Revfy , kernel-hardening@lists.openwall.com, linux-arch Message-ID: <20151209214318.yMNtk-LzmZmyBJkQma2cEtsGCW5DddH_hOBBCPjhXA0@z> 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 Cc: Rasmus Villemoes Cc: Daniel Borkmann --- 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"). * 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; + 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; } -- 1.9.1