From owner-freebsd-bugs Sun May 13 12:55:10 2001 Delivered-To: freebsd-bugs@freebsd.org Received: from alpo.whistle.com (s206m1.whistle.com [207.76.206.1]) by hub.freebsd.org (Postfix) with ESMTP id 4011A37B42C; Sun, 13 May 2001 12:55:02 -0700 (PDT) (envelope-from mark-ml@whistle.com) Received: from [10.1.10.118] (PBG4.whistle.com [207.76.207.129]) by alpo.whistle.com (8.9.1a/8.9.1) with ESMTP id MAA63111; Sun, 13 May 2001 12:50:20 -0700 (PDT) Mime-Version: 1.0 X-Sender: mark-ml@207.76.206.1 Message-Id: In-Reply-To: <200105091630.f49GU3s07584@freefall.freebsd.org> References: <200105091630.f49GU3s07584@freefall.freebsd.org> Date: Sun, 13 May 2001 12:50:18 -0700 To: Gregory Neil Shapiro , freebsd-bugs@FreeBSD.ORG From: Mark Peek Subject: Re: bin/26619: m4 silently truncates long strings Content-Type: text/plain; charset="us-ascii" ; format="flowed" Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org At 9:30 AM -0700 5/9/01, Gregory Neil Shapiro wrote: > I have a fix but since I am not an expert on the m4 internals (damn, should > have taken compilers in college), I didn't want to blindly commit it. This > fixes the problem (to be honest, it's changes the problem from 512 > characters to 4096 characters). However, I don't know if it introduces any > side effects. It may be possible that some of the code was depending on > MAXSTR being 512 and changing it introduces a buffer overflow. If you increase the MAXSTR you should probably bump STRSPMAX as well. However, here's a patch that should fix the substr problem. Please give it a try and let me know if it works for you. With this change, you can even set MAXSTR/MAXTOK down to a lower number (I tried 20) and your test case will work correctly. I have another patch to remove the MAXTOK constant but there are other hard coded limitations that need to be excised out. Index: eval.c =================================================================== RCS file: /home/ncvs/src/usr.bin/m4/eval.c,v retrieving revision 1.10.2.1 diff -u -r1.10.2.1 eval.c --- eval.c 2001/02/18 02:26:19 1.10.2.1 +++ eval.c 2001/05/13 19:15:54 @@ -717,22 +717,22 @@ 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); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message