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:
Gregory Neil Shapiro 2001-05-18 18:35:34 +00:00
parent d3ebe37cd0
commit 4ba4d3873a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=76822

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);
}