diff options
author | gshapiro <gshapiro@FreeBSD.org> | 2001-05-18 18:35:34 +0000 |
---|---|---|
committer | gshapiro <gshapiro@FreeBSD.org> | 2001-05-18 18:35:34 +0000 |
commit | 52011546853a4017a1fa9778c7dd75ab0eab6bd6 (patch) | |
tree | 22e30c5dcd138d30a601385a7ab1e9e92fe62e3c /usr.bin/m4 | |
parent | bac609c202ccd3f77baec4e2cbba8f8c8756af98 (diff) | |
download | FreeBSD-src-52011546853a4017a1fa9778c7dd75ab0eab6bd6.zip FreeBSD-src-52011546853a4017a1fa9778c7dd75ab0eab6bd6.tar.gz |
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
Diffstat (limited to 'usr.bin/m4')
-rw-r--r-- | usr.bin/m4/eval.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c index e424815..d2ac3c8 100644 --- a/usr.bin/m4/eval.c +++ b/usr.bin/m4/eval.c @@ -717,22 +717,22 @@ register int argc; register unsigned char *ap, *fc, *k; register int nc; + 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 = MAXTOK; + nc = strlen(fc); 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 (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); } |