From patchwork Mon Jun 18 19:29:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 10472619 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 618A6600CC for ; Mon, 18 Jun 2018 19:29:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F377286AD for ; Mon, 18 Jun 2018 19:29:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4400F28BAF; Mon, 18 Jun 2018 19:29:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF9D7286AD for ; Mon, 18 Jun 2018 19:29:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935859AbeFRT3t (ORCPT ); Mon, 18 Jun 2018 15:29:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37938 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935743AbeFRT3s (ORCPT ); Mon, 18 Jun 2018 15:29:48 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 985CB30820C5 for ; Mon, 18 Jun 2018 19:29:48 +0000 (UTC) Received: from [IPv6:::1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B3325B681 for ; Mon, 18 Jun 2018 19:29:48 +0000 (UTC) To: linux-xfs From: Eric Sandeen Subject: [PATCH] mkfs: explicitly warn about unknown token failures Message-ID: <1b2f2674-d6ef-4354-057e-f476ac2e2a83@redhat.com> Date: Mon, 18 Jun 2018 14:29:47 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 18 Jun 2018 19:29:48 +0000 (UTC) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Rather than a generic "Error parsing line" for an unknown token within a section, issue a more helpful error message, i.e. [data] foo=1 would yield: Invalid token in section [data] at line /etc/xfs/mkfs/default:2 : foo Signed-off-by: Eric Sandeen Reviewed-by: Luis R. Rodriguez --- I may make one more pass over all these error messages because they seem a little hard to parse, but for now this matches the others, in general. i.e. i'd rather have: Invalid section "[splat]" at /etc/xfs/mkfs/default:1 ... Invalid token "foo" in section [data] at /etc/xfs/mkfs/default:2 or something like that, but I'll try to make any textual changes file-wide if they seem warranted. -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/mkfs/config.c b/mkfs/config.c index 9954691..70d752c 100644 --- a/mkfs/config.c +++ b/mkfs/config.c @@ -466,9 +466,6 @@ _("No section specified yet on line %s:%zu : %s\n"), */ snprintf(p, len, "%s=%lu", tag, value); - /* Not needed anymore */ - free(tag); - /* * We only use getsubopt() to validate the possible * subopt, we already parsed the value and its already @@ -476,6 +473,16 @@ _("No section specified yet on line %s:%zu : %s\n"), */ subopt = getsubopt(&p, (char **) confopt->subopts, &ignore_value); + if (subopt == -1) { + errno = EINVAL; + fprintf(stderr, +_("Invalid token in section [%s] at line %s:%zu : %s\n"), + confopt->name, config_file, lineno, tag); + goto out_free_tag; + } + + /* Not needed anymore */ + free(tag); ret = confopt->parser(dft, subopt, value); if (ret) {