Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1320720

[PATCH 2/3] lib: add "on" and "off" to strtobool

From Kees Cook <keescook@chromium.org>
Newsgroups linux.kernel
Subject [PATCH 2/3] lib: add "on" and "off" to strtobool
Date 2016-01-28 15:20 +0100
Message-ID <qVVAu-4Ce-13@gated-at.bofh.it> (permalink)
References <qVVAt-4Ce-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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 | 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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/3] lib: add "on" and "off" to strtobool Kees Cook <keescook@chromium.org> - 2016-01-28 15:20 +0100
  [PATCH 1/3] lib: fix callers of strtobool to use char array Kees Cook <keescook@chromium.org> - 2016-01-28 15:20 +0100
    Re: [PATCH 1/3] lib: fix callers of strtobool to use char array Andy Shevchenko <andy.shevchenko@gmail.com> - 2016-02-01 14:20 +0100
      Re: [PATCH 1/3] lib: fix callers of strtobool to use char array Kees Cook <keescook@chromium.org> - 2016-02-04 20:00 +0100
  [PATCH 2/3] lib: add "on" and "off" to strtobool Kees Cook <keescook@chromium.org> - 2016-01-28 15:20 +0100
  [PATCH 3/3] param: convert some "on"/"off" users to strtobool Kees Cook <keescook@chromium.org> - 2016-01-28 15:30 +0100
    Re: [PATCH 3/3] param: convert some "on"/"off" users to strtobool Heiko Carstens <heiko.carstens@de.ibm.com> - 2016-01-28 16:30 +0100
    Re: [PATCH 3/3] param: convert some "on"/"off" users to strtobool Michael Ellerman <mpe@ellerman.id.au> - 2016-01-29 04:20 +0100

csiph-web