From patchwork Tue Oct 21 08:31:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 5111371 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 94EB7C11AC for ; Tue, 21 Oct 2014 08:31:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BF71220148 for ; Tue, 21 Oct 2014 08:31:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BFAAD200CF for ; Tue, 21 Oct 2014 08:31:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754409AbaJUIbX (ORCPT ); Tue, 21 Oct 2014 04:31:23 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:59655 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751959AbaJUIbV (ORCPT ); Tue, 21 Oct 2014 04:31:21 -0400 X-IronPort-AV: E=Sophos;i="5.04,760,1406563200"; d="scan'208";a="37646704" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Oct 2014 16:28:13 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s9L8VEx1032449 for ; Tue, 21 Oct 2014 16:31:14 +0800 Received: from adam-work.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 21 Oct 2014 16:31:22 +0800 From: Qu Wenruo To: Subject: [PATCH v2] btrfs-progs: Fix number of arguments check of 'btrfs fi df' Date: Tue, 21 Oct 2014 16:31:17 +0800 Message-ID: <1413880277-19691-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.1.2 MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 'btrfs fi df' needs exactly one arguments as mount option, but as 3.17 we can run 'btrfs fi df' without any argument, and it will error as "ERROR: can't access '%s'" which means the argument number does not do what it should. The bug is caused by manually modify the optind and use check_argc_max() instead of the original check_argc_exact(). This patch fixes it by not modifying the optind and use check_argc_exact() again. Signed-off-by: Qu Wenruo --- changlog: v2: Don't introduce opt_num, use optind directly --- cmds-filesystem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index bb5881e..70223d8 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -241,7 +241,6 @@ static int cmd_df(int argc, char **argv) DIR *dirstream = NULL; unsigned unit_mode = UNITS_DEFAULT; - optind = 1; while (1) { int long_index; static const struct option long_options[] = { @@ -290,7 +289,7 @@ static int cmd_df(int argc, char **argv) } } - if (check_argc_max(argc, optind + 1)) + if (check_argc_exact(argc, optind + 1)) usage(cmd_df_usage); path = argv[optind];