From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933902AbcATCJw (ORCPT ); Tue, 19 Jan 2016 21:09:52 -0500 Received: from smtprelay0016.hostedemail.com ([216.40.44.16]:44295 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933337AbcATCJm (ORCPT ); Tue, 19 Jan 2016 21:09:42 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::::::::::,RULES_HIT:41:355:379:541:599:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2689:2693:2828:2895:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3872:4321:5007:6261:6742:7903:8957:10004:10400:10848:11232:11658:11783:11914:12517:12519:12740:13069:13311:13357:13894:14659:21080:21324:30003:30054:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: nest33_716836638974f X-Filterd-Recvd-Size: 2890 Message-ID: <1453255778.25071.26.camel@perches.com> Subject: Re: [PATCH v4 2/8] lib: add "on" and "off" to strtobool From: Joe Perches To: Kees Cook , Ingo Molnar Cc: 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 Date: Tue, 19 Jan 2016 18:09:38 -0800 In-Reply-To: <1453226922-16831-3-git-send-email-keescook@chromium.org> References: <1453226922-16831-1-git-send-email-keescook@chromium.org> <1453226922-16831-3-git-send-email-keescook@chromium.org> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.3-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2016-01-19 at 10:08 -0800, Kees Cook wrote: > Several places in the kernel expect to use "on" and "off" for their > boolean signifiers, so add them to strtobool. Several places in the kernel use a char address like fs/cifs/cifs_debug.c char c; ... if (strtobool(&c, ...)) Using s[1] might cause problems for those uses. > diff --git 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': Perhaps switch (tolower(s[1])) { is more readable > + *res = false; > + break; > + default: > + return -EINVAL; > + } > + break; or maybe /* fallthrough */ >   default: >   return -EINVAL; >   }