Avoid falling off the end of a fixed-length array (from John F. Woods; PR#1431).

This commit is contained in:
pk 1995-09-15 00:32:33 +00:00
parent 84c517c128
commit 7b44b2859d
2 changed files with 21 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ftp_var.h,v 1.6 1995/09/08 01:06:32 tls Exp $ */
/* $NetBSD: ftp_var.h,v 1.7 1995/09/15 00:32:35 pk Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@ -99,7 +99,8 @@ char *stringbase; /* current scan point in line buffer */
char argbuf[200]; /* argument storage buffer */
char *argbase; /* current storage point in arg buffer */
int margc; /* count of arguments on input line */
char *margv[20]; /* args parsed from input line */
char **margv; /* args parsed from input line */
int margvlen; /* how large margv is currently */
int cpend; /* flag: if != 0, then pending server reply */
int mflag; /* flag: if != 0, then active multi command */

View File

@ -41,7 +41,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
static char rcsid[] = "$NetBSD: main.c,v 1.9 1995/09/14 01:39:52 cgd Exp $";
static char rcsid[] = "$NetBSD: main.c,v 1.10 1995/09/15 00:32:33 pk Exp $";
#endif
#endif /* not lint */
@ -320,13 +320,27 @@ makeargv()
{
char **argp;
margc = 0;
argp = margv;
stringbase = line; /* scan from first of buffer */
argbase = argbuf; /* store from first of buffer */
slrflag = 0;
while (*argp++ = slurpstring())
margc++;
for (margc = 0; ; margc++) {
/* Expand array if necessary */
if (margc == margvlen) {
margv = (margvlen == 0)
? (char **)malloc(20 * sizeof(char *))
: (char **)realloc(margv,
(margvlen + 20)*sizeof(char *));
if (margv == NULL)
errx(1, "cannot realloc argv array");
margvlen += 20;
argp = margv + margc;
}
if ((*argp++ = slurpstring()) == NULL)
break;
}
}
/*