From patchwork Thu Jan 28 14:17:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 8150811 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 26DF8BEEE5 for ; Thu, 28 Jan 2016 14:18:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4056B20220 for ; Thu, 28 Jan 2016 14:18:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 638E92021A for ; Thu, 28 Jan 2016 14:18:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755429AbcA1OSl (ORCPT ); Thu, 28 Jan 2016 09:18:41 -0500 Received: from mail-pf0-f182.google.com ([209.85.192.182]:36363 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752733AbcA1OR5 (ORCPT ); Thu, 28 Jan 2016 09:17:57 -0500 Received: by mail-pf0-f182.google.com with SMTP id n128so24157959pfn.3 for ; Thu, 28 Jan 2016 06:17:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Vjy1WqimY6qYH7qA02t1tESV6DoJlkYsQRkueRtgdQU=; b=F1zFkCXLR7rZS5oHa4xJSEyKZnwbWN8UxYb/fOTwugPjp5PDXWHpgq8HL3jF5TTKaD IMcIFzhPUw0xk8aYZ8m88I6A66SHJZj7sc3kvXKs/KX+LiQ8vbi02oKwyh/5GUdnTn12 KLaGWHVhoAP1kjNbzR3TMmHfgWViiThbUAW70= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Vjy1WqimY6qYH7qA02t1tESV6DoJlkYsQRkueRtgdQU=; b=f1cmx1q+O73096rH0QxP9NbuE0Pf2X1Y4pTPyfwqNIr4tNnNioSVodG5OxuR2enada tK5OH3XgR3JQZM1RNXbHqlj/JxwmyGuOXwPAgK8eYlkMgq1SaFVXRcgFzcozNhvjyshY BoZqG2nle5bSQs1cEkSbKM1Lac/FuZVbKQ7X6XJgyfwxj1MwcgdjJycojQBHMdm00xk0 SIKpbhgA/c1LtWNE+dd5hhaliyReVGOj6w3VWF9o1wMyCHXdV4i9gRjj9I5GQ2ymLr2W zlxJO0qUS1tHtxP03fe5w54NmU/4D5Hm1vE3RwEf20evc1xSF3t3/pU1Pbivm8vf95k3 4t3g== X-Gm-Message-State: AG10YORV50gkT5yHMYcfJHzbvo+TT20Tusp0jDJ80R23fIckyvNRhEA6HNvBvweCUDgm1g== X-Received: by 10.98.13.85 with SMTP id v82mr4795642pfi.158.1453990664503; Thu, 28 Jan 2016 06:17:44 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id cq4sm16845017pad.28.2016.01.28.06.17.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jan 2016 06:17:43 -0800 (PST) From: Kees Cook To: Andrew Morton Cc: Kees Cook , Rasmus Villemoes , Daniel Borkmann , Joe Perches , Amitkumar Karwar , Nishant Sarmukadam , Kalle Valo , Steve French , Michael Ellerman , Heiko Carstens , Martin Schwidefsky , x86@kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] lib: add "on" and "off" to strtobool Date: Thu, 28 Jan 2016 06:17:06 -0800 Message-Id: <1453990627-19164-3-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.6.3 In-Reply-To: <1453990627-19164-1-git-send-email-keescook@chromium.org> References: <1453990627-19164-1-git-send-email-keescook@chromium.org> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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; }