Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 May 2001 12:50:18 -0700
From:      Mark Peek <mark-ml@whistle.com>
To:        Gregory Neil Shapiro <gshapiro@FreeBSD.ORG>, freebsd-bugs@FreeBSD.ORG
Subject:   Re: bin/26619: m4 silently truncates long strings
Message-ID:  <p05100302b724935e9399@[10.1.10.118]>
In-Reply-To: <200105091630.f49GU3s07584@freefall.freebsd.org>
References:  <200105091630.f49GU3s07584@freefall.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p05100302b724935e9399>