summaryrefslogtreecommitdiff
path: root/src/argparse.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2020-02-20 14:52:43 +0100
committerWerner Koch <wk@gnupg.org>2020-02-20 14:52:43 +0100
commit44258227f7dfb12b3c0faa8ab417a9dc2be46eed (patch)
tree01b0c2f5523316250c741674ce8e8fe875079c67 /src/argparse.c
parent46b3749997da84c41f583b22cda812dd5e42bde0 (diff)
downloadlibgpg-error-44258227f7dfb12b3c0faa8ab417a9dc2be46eed.tar.gz
core: Skip cmdline parsing for no or an empty argv.
* src/argparse.c (_gpgrt_argparser): Allow for empty argv. Also fix memory leak. -- This comes handy when rereading option files on SIGHUP, for example in gpg-agent. There is no need to provide a dummy array. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src/argparse.c')
-rw-r--r--src/argparse.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/argparse.c b/src/argparse.c
index dc3cb15..1ab4526 100644
--- a/src/argparse.c
+++ b/src/argparse.c
@@ -935,19 +935,22 @@ _gpgrt_argparser (gpgrt_argparse_t *arg, gpgrt_opt_t *opts,
switch (arg->internal->state)
{
case STATE_init:
- if (any_opt_conffile (opts))
+ if (arg->argc && arg->argv && *arg->argc
+ && any_opt_conffile (opts))
{
/* The list of option allow for conf files
* (e.g. gpg's "--option FILE" and "--no-options")
- * Now check whether one was really given on the
- * command line. */
+ * Now check whether one was really given on the command
+ * line. Note that we don't need to run this code if no
+ * argument array was provided. */
int save_argc = *arg->argc;
char **save_argv = *arg->argv;
unsigned int save_flags = arg->flags;
int save_idx = arg->internal->idx;
int any_no_conffile = 0;
- arg->flags = (ARGPARSE_FLAG_KEEP | ARGPARSE_FLAG_NOVERSION);
+ arg->flags = (ARGPARSE_FLAG_KEEP | ARGPARSE_FLAG_NOVERSION
+ | ARGPARSE_FLAG__INITIALIZED);
while (arg_parse (arg, opts, 1))
{
if ((arg->internal->opt_flags & ARGPARSE_OPT_CONFFILE))
@@ -1118,6 +1121,12 @@ _gpgrt_argparser (gpgrt_argparse_t *arg, gpgrt_opt_t *opts,
arg->internal->idx = 0;
arg->internal->stopped = 0;
arg->internal->inarg = 0;
+ if (!arg->argc || !arg->argv || !*arg->argv)
+ {
+ /* No or empty argument vector - don't bother to parse things. */
+ arg->internal->state = STATE_finished;
+ goto next_state;
+ }
arg->r_opt = ARGPARSE_CONFFILE;
arg->r_type = ARGPARSE_TYPE_NONE;
arg->r.ret_str = NULL;