From 8228085c540edbe822529699025641a05fae383f Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 11 May 2015 13:11:17 +0100 Subject: [PATCH] Unix Pageant: move handling of --exec arguments. Now --exec instantly terminates option processing, by treating everything after it as the command. This means it doesn't matter if the --exec command word looks like another option, and it also means we can simplify the handling of real non-option argument words, when I get round to adding some for loading keys. --- unix/uxpgnt.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/unix/uxpgnt.c b/unix/uxpgnt.c index eb7f0359..c1a094ce 100644 --- a/unix/uxpgnt.c +++ b/unix/uxpgnt.c @@ -266,7 +266,7 @@ int main(int argc, char **argv) /* * Process the command line. */ - while (--argc) { + while (--argc > 0) { char *p = *++argv; if (*p == '-' && doing_opts) { if (!strcmp(p, "-V") || !strcmp(p, "--version")) { @@ -286,17 +286,21 @@ int main(int argc, char **argv) life = LIFE_PERM; } else if (!strcmp(p, "--exec")) { life = LIFE_EXEC; + /* Now all subsequent arguments go to the exec command. */ + if (--argc > 0) { + exec_args = ++argv; + argc = 0; /* force end of option processing */ + } else { + fprintf(stderr, "pageant: expected a command " + "after --exec\n"); + exit(1); + } } else if (!strcmp(p, "--")) { doing_opts = FALSE; } } else { - if (life == LIFE_EXEC) { - exec_args = argv; - break; /* everything else is now args to the exec command */ - } else { - fprintf(stderr, "pageant: unexpected argument '%s'\n", p); - exit(1); - } + fprintf(stderr, "pageant: unexpected argument '%s'\n", p); + exit(1); } }