From patchwork Wed Nov 25 12:08:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 7698551 Return-Path: X-Original-To: patchwork-linux-btrfs@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 2CC27BF90C for ; Wed, 25 Nov 2015 12:09:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6A3F7208D1 for ; Wed, 25 Nov 2015 12:09:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D3312084C for ; Wed, 25 Nov 2015 12:09:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753639AbbKYMJc (ORCPT ); Wed, 25 Nov 2015 07:09:32 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:20697 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751637AbbKYMI4 (ORCPT ); Wed, 25 Nov 2015 07:08:56 -0500 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id tAPC8dWf014596 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 25 Nov 2015 12:08:39 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id tAPC8cJn031329 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Wed, 25 Nov 2015 12:08:39 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id tAPC8c6p032222; Wed, 25 Nov 2015 12:08:38 GMT Received: from arch2.sg.oracle.com (/10.186.101.159) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 25 Nov 2015 04:08:37 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, calestyo@scientia.net, ahferroin7@gmail.com, 1i5t5.duncan@cox.net Subject: [PATCH 4/7] btrfs-progs: check for numerical in version_to_code() Date: Wed, 25 Nov 2015 20:08:17 +0800 Message-Id: <1448453300-8449-5-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1448453300-8449-1-git-send-email-anand.jain@oracle.com> References: <1448453300-8449-1-git-send-email-anand.jain@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 As the version is now being passed by user it should be checked if its numerical. We didn't need this before as version wasn't passed by used. So this is not a bug fix. Signed-off-by: Anand Jain --- utils.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/utils.c b/utils.c index 0e66e2b..216efa6 100644 --- a/utils.c +++ b/utils.c @@ -3119,14 +3119,18 @@ static int version_to_code(char *v) for (b[i] = strtok_r(v, ".", &save_b); b[i] != NULL; - b[i] = strtok_r(NULL, ".", &save_b)) + b[i] = strtok_r(NULL, ".", &save_b)) { + if (!is_numerical(b[i])) + return -EINVAL; i++; + } + if (b[1] == NULL) + return KERNEL_VERSION(atoi(b[0]), 0, 0); if (b[2] == NULL) return KERNEL_VERSION(atoi(b[0]), atoi(b[1]), 0); - else - return KERNEL_VERSION(atoi(b[0]), atoi(b[1]), atoi(b[2])); + return KERNEL_VERSION(atoi(b[0]), atoi(b[1]), atoi(b[2])); } static int get_kernel_code()