String operations could silently truncate long strings, leaving the output

corrupted.  Mark's patch fixes this be removing the MAXTOK limitation on
substring operations and allowing the putback buffer size to be the limiting
factor.  If the putback buffer size if reached, m4 gives an error instead of
silently truncating the string.

PR:		bin/26619
Submitted by:	Mark Peek <mark-ml@whistle.com>
MFC after:	5 days
This commit is contained in:
gshapiro 2001-05-18 18:35:34 +00:00
parent bac609c202
commit 5201154685

View File

@ -717,22 +717,22 @@ register int argc;
register unsigned char *ap, *fc, *k;
register int nc;
if (argc < 5)
nc = MAXTOK;
else
#ifdef EXPR
nc = expr(argv[4]);
#else
nc = atoi(argv[4]);
#endif
ap = argv[2]; /* target string */
#ifdef EXPR
fc = ap + expr(argv[3]); /* first char */
#else
fc = ap + atoi(argv[3]); /* first char */
#endif
if (argc < 5)
nc = strlen(fc);
else
#ifdef EXPR
nc = expr(argv[4]);
#else
nc = atoi(argv[4]);
#endif
if (fc >= ap && fc < ap + strlen(ap))
for (k = fc + min(nc, strlen(fc)) - 1; k >= fc; k--)
for (k = fc + nc - 1; k >= fc; k--)
putback(*k);
}