From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kees Cook Subject: [PATCH v4 2/8] lib: add "on" and "off" to strtobool Date: Tue, 19 Jan 2016 10:08:36 -0800 Message-ID: <1453226922-16831-3-git-send-email-keescook@chromium.org> References: <1453226922-16831-1-git-send-email-keescook@chromium.org> Reply-To: kernel-hardening@lists.openwall.com Return-path: List-Post: List-Help: List-Unsubscribe: List-Subscribe: In-Reply-To: <1453226922-16831-1-git-send-email-keescook@chromium.org> To: Ingo Molnar Cc: Kees Cook , Rasmus Villemoes , Daniel Borkmann , 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-kernel@vger.kernel.org, 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 | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/string.c b/lib/string.c index 0323c0d5629a..091570708db7 100644 --- a/lib/string.c +++ b/lib/string.c @@ -635,12 +635,15 @@ EXPORT_SYMBOL(sysfs_streq); * @s: input string * @res: result * - * This routine returns 0 iff the first character is one of 'Yy1Nn0'. - * Otherwise it will return -EINVAL. Value pointed to by res is - * updated upon finding a match. + * This routine returns 0 iff the first character is one of 'Yy1Nn0', or + * [oO][NnFf] 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 +655,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; } -- 2.6.3 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f169.google.com ([209.85.192.169]:35472 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932767AbcASSJZ (ORCPT ); Tue, 19 Jan 2016 13:09:25 -0500 Received: by mail-pf0-f169.google.com with SMTP id 65so179168486pff.2 for ; Tue, 19 Jan 2016 10:09:25 -0800 (PST) From: Kees Cook Subject: [PATCH v4 2/8] lib: add "on" and "off" to strtobool Date: Tue, 19 Jan 2016 10:08:36 -0800 Message-ID: <1453226922-16831-3-git-send-email-keescook@chromium.org> In-Reply-To: <1453226922-16831-1-git-send-email-keescook@chromium.org> References: <1453226922-16831-1-git-send-email-keescook@chromium.org> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Ingo Molnar Cc: Kees Cook , Rasmus Villemoes , Daniel Borkmann , 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-kernel@vger.kernel.org, linux-arch Message-ID: <20160119180836.vKxmA2xtQAej5gsVFFhrYUgmoSEN-gRInkTFjVzgKOE@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 | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/string.c b/lib/string.c index 0323c0d5629a..091570708db7 100644 --- a/lib/string.c +++ b/lib/string.c @@ -635,12 +635,15 @@ EXPORT_SYMBOL(sysfs_streq); * @s: input string * @res: result * - * This routine returns 0 iff the first character is one of 'Yy1Nn0'. - * Otherwise it will return -EINVAL. Value pointed to by res is - * updated upon finding a match. + * This routine returns 0 iff the first character is one of 'Yy1Nn0', or + * [oO][NnFf] 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 +655,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; } -- 2.6.3