aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2020-04-29 14:18:59 +0200
committerAndreas Schneider <asn@cryptomilk.org>2020-05-05 14:23:06 +0200
commit2e7ca3e8a6e1ae4dddd04d9d68197b2f8f87bf6d (patch)
treea1fe6e57b39add98a58177856a16b19b05ad49ab /src
parentb90131dfe696b40b7cc0bc18cdfc307e6d14480a (diff)
downloadlibssh-2e7ca3e8a6e1ae4dddd04d9d68197b2f8f87bf6d.tar.gz
libssh-2e7ca3e8a6e1ae4dddd04d9d68197b2f8f87bf6d.tar.xz
libssh-2e7ca3e8a6e1ae4dddd04d9d68197b2f8f87bf6d.zip
options: Properly handle unknown options with arguments
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r--src/options.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/options.c b/src/options.c
index b5f951ac..f5c7bbb2 100644
--- a/src/options.c
+++ b/src/options.c
@@ -1217,6 +1217,11 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv)
int saveopterr = opterr;
int opt;
+ /* Nothing to do here */
+ if (argc <= 1) {
+ return SSH_OK;
+ }
+
opterr = 0; /* shut up getopt */
while((opt = getopt(argc, argv, "c:i:Cl:p:vb:rd12")) != -1) {
switch(opt) {
@@ -1266,8 +1271,19 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv)
return -1;
}
current++;
- if (optarg) {
- save[current++] = argv[optind + 1];
+ /* We can not use optarg here as getopt does not set it for
+ * unknown options. We need to manually extract following
+ * option and skip it manually from further processing */
+ if (optind < argc && argv[optind][0] != '-') {
+ tmp = realloc(save, (current + 1) * sizeof(char*));
+ if (tmp == NULL) {
+ SAFE_FREE(save);
+ ssh_set_error_oom(session);
+ return -1;
+ }
+ save = tmp;
+ save[current++] = argv[optind];
+ optind++;
}
}
} /* switch */