summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-06-02 18:34:39 +0200
committerAndreas Schneider <asn@cryptomilk.org>2013-06-02 18:34:39 +0200
commite41482fec418457be9288ca5ce9df2099079c6da (patch)
tree56b19b2257d2baa25bb26dee6d4f88bd137b2aae /src
parent992f00b1456cf9c416d9b89bf7b97f2f7e02566a (diff)
downloadlibssh-e41482fec418457be9288ca5ce9df2099079c6da.tar.gz
libssh-e41482fec418457be9288ca5ce9df2099079c6da.tar.xz
libssh-e41482fec418457be9288ca5ce9df2099079c6da.zip
opts: Fix segfault in option parser.
Diffstat (limited to 'src')
-rw-r--r--src/options.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/options.c b/src/options.c
index c43e41d..931cb31 100644
--- a/src/options.c
+++ b/src/options.c
@@ -931,7 +931,7 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv) {
char *cipher = NULL;
char *identity = NULL;
char *port = NULL;
- char **save = NULL;
+ char **save = NULL, **tmp;
int i = 0;
int argc = *argcptr;
int debuglevel = 0;
@@ -990,7 +990,6 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv) {
break;
default:
{
- char **tmp;
char opt[3]="- ";
opt[1] = optopt;
tmp = realloc(save, (current + 1) * sizeof(char*));
@@ -1015,7 +1014,16 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv) {
} /* while */
opterr = saveopterr;
while (optind < argc) {
- save[current++] = argv[optind++];
+ 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];
+ current++;
+ optind++;
}
if (usersa && usedss) {