From 4ab5e1de84ab966e4a25c1c23337a6fae3d8070e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 8 Feb 2025 20:56:48 +0100 Subject: Fix option parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- sshexec.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'sshexec.c') diff --git a/sshexec.c b/sshexec.c index bc02987..7f49530 100644 --- a/sshexec.c +++ b/sshexec.c @@ -580,11 +580,12 @@ parse_ssh_options(char *argv[], size_t *nopts_out) } } else { /* Short option */ + char opt; arg++; - while (*arg) { - if (strchr(unarged_opts, *arg)) { + while ((opt = *arg++)) { + if (strchr(unarged_opts, opt)) { /* Option cannot have an argument */ - } else if (strchr(arged_opts, *arg)) { + } else if (strchr(arged_opts, opt)) { /* Option must have an argument */ if (arg[1]) { /* Argument is attached to option */ @@ -595,18 +596,18 @@ parse_ssh_options(char *argv[], size_t *nopts_out) nopts++; break; } else { - exitf("%s: argument missing for option -%c\n", argv0, *arg); + exitf("%s: argument missing for option -%c\n", argv0, opt); } - } else if (strchr(optatarged_opts, *arg)) { + } else if (strchr(optatarged_opts, opt)) { /* Option may have an attached argument, but it cannot have a detached argument */ break; - } else if (strchr(optarged_opts, *arg)) { + } else if (strchr(optarged_opts, opt)) { /* Option may have an attached or detached argument */ - if (arg[1]) { + if (*arg) { /* Argument is attached to option */ } else { /* Either there is no argument, or it is detached from the option */ - if (argv[1] && argv[1][0] != '-') { + if (*argv && **argv != '-') { /* Argument exist and is detached. We assume that if the next * argument in the command line is the option's argument unless * it starts with '-'. */ @@ -616,7 +617,7 @@ parse_ssh_options(char *argv[], size_t *nopts_out) } } } else { - exitf("%s: unrecognised option -%c\n", argv0, *arg); + exitf("%s: unrecognised option -%c\n", argv0, opt); } } } -- cgit v1.2.3-70-g09d2