1
1

opts: Fix segfault in option parser.

Этот коммит содержится в:
Andreas Schneider 2013-06-02 18:34:39 +02:00
родитель 992f00b145
Коммит e41482fec4

Просмотреть файл

@ -931,7 +931,7 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv) {
char *cipher = NULL; char *cipher = NULL;
char *identity = NULL; char *identity = NULL;
char *port = NULL; char *port = NULL;
char **save = NULL; char **save = NULL, **tmp;
int i = 0; int i = 0;
int argc = *argcptr; int argc = *argcptr;
int debuglevel = 0; int debuglevel = 0;
@ -990,7 +990,6 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv) {
break; break;
default: default:
{ {
char **tmp;
char opt[3]="- "; char opt[3]="- ";
opt[1] = optopt; opt[1] = optopt;
tmp = realloc(save, (current + 1) * sizeof(char*)); tmp = realloc(save, (current + 1) * sizeof(char*));
@ -1015,7 +1014,16 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv) {
} /* while */ } /* while */
opterr = saveopterr; opterr = saveopterr;
while (optind < argc) { 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) { if (usersa && usedss) {