diff options
| author | Mattias Andrée <m@maandree.se> | 2025-02-08 20:56:48 +0100 | 
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2025-02-08 20:56:48 +0100 | 
| commit | 4ab5e1de84ab966e4a25c1c23337a6fae3d8070e (patch) | |
| tree | a7f086a423307dd4aa3aca0bab73f6d01a8151c7 | |
| parent | Fix makefile install rule (diff) | |
| download | sshexec-4ab5e1de84ab966e4a25c1c23337a6fae3d8070e.tar.gz sshexec-4ab5e1de84ab966e4a25c1c23337a6fae3d8070e.tar.bz2 sshexec-4ab5e1de84ab966e4a25c1c23337a6fae3d8070e.tar.xz | |
Fix option parsing1.2
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
| -rw-r--r-- | sshexec.c | 19 | 
1 files changed, 10 insertions, 9 deletions
| @@ -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);  				}  			}  		} | 
