From 4940ba14100ad11b0ed1f2a8a4fea5daa34d56ee Mon Sep 17 00:00:00 2001 From: Pavel Březina Date: Thu, 29 Oct 2015 15:15:15 +0100 Subject: sss_tools: do not allow unexpected free argument Reviewed-by: Pavel Reichl --- src/tools/common/sss_tools.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/tools/common/sss_tools.c b/src/tools/common/sss_tools.c index abb9dbace..d3073a2e5 100644 --- a/src/tools/common/sss_tools.c +++ b/src/tools/common/sss_tools.c @@ -292,6 +292,7 @@ int sss_tool_popt_ex(struct sss_cmdline *cmdline, POPT_AUTOHELP POPT_TABLEEND }; + const char *fopt; char *help; poptContext pc; int ret; @@ -337,9 +338,9 @@ int sss_tool_popt_ex(struct sss_cmdline *cmdline, } /* Parse free option which is always required if requested. */ + fopt = poptGetArg(pc); if (_fopt != NULL) { - *_fopt = poptGetArg(pc); - if (*_fopt == NULL) { + if (fopt == NULL) { fprintf(stderr, _("Missing option: %s\n\n"), fopt_help); poptPrintHelp(pc, stderr, 0); ret = EXIT_FAILURE; @@ -353,6 +354,14 @@ int sss_tool_popt_ex(struct sss_cmdline *cmdline, ret = EXIT_FAILURE; goto done; } + + *_fopt = fopt; + } else if (_fopt == NULL && fopt != NULL) { + /* Unexpected free argument. */ + fprintf(stderr, _("Unexpected parameter: %s\n\n"), fopt); + poptPrintHelp(pc, stderr, 0); + ret = EXIT_FAILURE; + goto done; } /* If at least one option is required and not provided, print error. */ -- cgit