diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2013-01-10 12:09:56 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2013-01-22 11:32:47 +0100 |
commit | 21a45e89c5839a6f25687359fb3c42a3123d33d8 (patch) | |
tree | c3f5f5ebe42146bd769f0e31fa9beac37d97a6b7 /src | |
parent | de096910b37ca3474fc37d421fb051a234f5cce0 (diff) | |
download | libssh-21a45e89c5839a6f25687359fb3c42a3123d33d8.tar.gz libssh-21a45e89c5839a6f25687359fb3c42a3123d33d8.tar.xz libssh-21a45e89c5839a6f25687359fb3c42a3123d33d8.zip |
options: Fix a free crash bug if we parse unknown options.
Thanks to Yong Chuan Koh, X-Force Research <kohyc@sg.ibm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/options.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/options.c b/src/options.c index c4589fe..c43e41d 100644 --- a/src/options.c +++ b/src/options.c @@ -953,12 +953,6 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv) { int saveoptind = optind; /* need to save 'em */ int saveopterr = opterr; - save = malloc(argc * sizeof(char *)); - if (save == NULL) { - ssh_set_error_oom(session); - return -1; - } - opterr = 0; /* shut up getopt */ while(cont && ((i = getopt(argc, argv, "c:i:Cl:p:vb:rd12")) != -1)) { switch(i) { @@ -996,8 +990,16 @@ 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*)); + if (tmp == NULL) { + SAFE_FREE(save); + ssh_set_error_oom(session); + return -1; + } + save = tmp; save[current] = strdup(opt); if (save[current] == NULL) { SAFE_FREE(save); |