From patchwork Thu Oct 30 15:10:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 5198341 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 2928CC11AC for ; Thu, 30 Oct 2014 15:11:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 51CE320173 for ; Thu, 30 Oct 2014 15:11:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 43A89200EC for ; Thu, 30 Oct 2014 15:11:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760235AbaJ3PK7 (ORCPT ); Thu, 30 Oct 2014 11:10:59 -0400 Received: from cantor2.suse.de ([195.135.220.15]:44141 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759963AbaJ3PK6 (ORCPT ); Thu, 30 Oct 2014 11:10:58 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 78922ABE2; Thu, 30 Oct 2014 15:10:55 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 3088EDA931; Thu, 30 Oct 2014 16:10:55 +0100 (CET) Date: Thu, 30 Oct 2014 16:10:55 +0100 From: David Sterba To: Qu Wenruo Cc: linux-btrfs@vger.kernel.org Subject: Re: [PATCH] btrfs-progs: Fix number of arguments check of 'btrfs fi df' Message-ID: <20141030151055.GB21354@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Qu Wenruo , linux-btrfs@vger.kernel.org References: <1413877333-14507-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1413877333-14507-1-git-send-email-quwenruo@cn.fujitsu.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) 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 On Tue, Oct 21, 2014 at 03:42:13PM +0800, Qu Wenruo wrote: > 'btrfs fi df' needs exactly one arguments as mount option, > and due to the introduce of human readable options, some check is not > valid now, the new optind can point to the ending NULL string. > > For example, you can run 'btrfs fi df' without any argument, and it will > error as "ERROR: can't access '%s'" which means the argument number > check is not valid. Thanks for catching it. > This patch will use the old check_argc_exact() but introduce opt_num to > record how many options is provided, ensuring there will be and only be > one mount point provided. > --- a/cmds-filesystem.c > +++ b/cmds-filesystem.c > @@ -237,11 +237,11 @@ static int cmd_df(int argc, char **argv) > struct btrfs_ioctl_space_args *sargs = NULL; > int ret; > int fd; > + int opt_num = 0; > char *path; > DIR *dirstream = NULL; > unsigned unit_mode = UNITS_DEFAULT; > > - optind = 1; > while (1) { > int long_index; > static const struct option long_options[] = { > @@ -257,6 +257,7 @@ static int cmd_df(int argc, char **argv) > &long_index); > if (c < 0) > break; > + opt_num++; > switch (c) { > case 'b': > unit_mode = UNITS_RAW; > @@ -290,7 +291,7 @@ static int cmd_df(int argc, char **argv) > } > } > > - if (check_argc_max(argc, optind + 1)) > + if (check_argc_exact(argc, 2 + opt_num)) Well, a simple change to check_argc_exact(argc, optind + 1) fixes it for me. The optind is supposed to track the argument index and you're duplicating it with opt_num. I'll commit it with this simplified version (and changelog updated): --- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -248,7 +248,7 @@ static int cmd_filesystem_df(int argc, char **argv) } } - if (check_argc_max(argc, optind + 1)) + if (check_argc_exact(argc, optind + 1)) usage(cmd_filesystem_df_usage); path = argv[optind];