From: Eric Sandeen Date: Tue, 19 Jun 2018 20:43:04 +0000 (-0500) Subject: mkfs: explicitly warn about unknown config token failures X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7eda100f42e15d0d60f4c946dbd3263c191b6ae2;p=thirdparty%2Fxfsprogs-dev.git mkfs: explicitly warn about unknown config token failures 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 Signed-off-by: Eric Sandeen --- diff --git a/mkfs/config.c b/mkfs/config.c index 9954691b0..70d752ce0 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) {