Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Sep 2019 15:35:34 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r352069 - head/usr.bin/m4
Message-ID:  <201909091535.x89FZYQ3010603@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Mon Sep  9 15:35:34 2019
New Revision: 352069
URL: https://svnweb.freebsd.org/changeset/base/352069

Log:
  m4: import from OpenBSD
  
  patch by espie@
  
  replace sloppy parsing of numeric values with strtonum (incr, decr, divert)
  
  still use integers, so use the natural bounds for these.
  
  POSIX says m4 should error when these use non numeric values, and now they
  do.
  
  okay millert@
  
  Obtained from:	OpenBSD

Modified:
  head/usr.bin/m4/eval.c

Modified: head/usr.bin/m4/eval.c
==============================================================================
--- head/usr.bin/m4/eval.c	Mon Sep  9 15:28:22 2019	(r352068)
+++ head/usr.bin/m4/eval.c	Mon Sep  9 15:35:34 2019	(r352069)
@@ -1,4 +1,4 @@
-/*	$OpenBSD: eval.c,v 1.76 2017/10/23 15:21:19 espie Exp $	*/
+/*	$OpenBSD: eval.c,v 1.77 2017/11/11 12:55:59 espie Exp $	*/
 /*	$NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $	*/
 
 /*-
@@ -126,6 +126,7 @@ void
 expand_builtin(const char *argv[], int argc, int td)
 {
 	int c, n;
+	const char *errstr;
 	int ac;
 	static int sysval = 0;
 
@@ -186,13 +187,15 @@ expand_builtin(const char *argv[], int argc, int td)
 		if (argc > 3) {
 			base = strtonum(argv[3], 2, 36, &errstr);
 			if (errstr) {
-				m4errx(1, "expr: base %s invalid.", argv[3]);
+				m4errx(1, "expr: base is %s: %s.",
+				    errstr, argv[3]);
 			}
 		}
 		if (argc > 4) {
 			maxdigits = strtonum(argv[4], 0, INT_MAX, &errstr);
 			if (errstr) {
-				m4errx(1, "expr: maxdigits %s invalid.", argv[4]);
+				m4errx(1, "expr: maxdigits is %s: %s.",
+				    errstr, argv[4]);
 			}
 		}
 		if (argc > 2)
@@ -231,8 +234,13 @@ expand_builtin(const char *argv[], int argc, int td)
 	 * doincr - increment the value of the
 	 * argument
 	 */
-		if (argc > 2)
-			pbnum(atoi(argv[2]) + 1);
+		if (argc > 2) {
+			n = strtonum(argv[2], INT_MIN, INT_MAX-1, &errstr);
+			if (errstr != NULL)
+				m4errx(1, "incr: argument is %s: %s.",
+				    errstr, argv[2]);
+			pbnum(n + 1);
+		}
 		break;
 
 	case DECRTYPE:
@@ -240,8 +248,13 @@ expand_builtin(const char *argv[], int argc, int td)
 	 * dodecr - decrement the value of the
 	 * argument
 	 */
-		if (argc > 2)
-			pbnum(atoi(argv[2]) - 1);
+		if (argc > 2) {
+			n = strtonum(argv[2], INT_MIN+1, INT_MAX, &errstr);
+			if (errstr)
+				m4errx(1, "decr: argument is %s: %s.",
+				    errstr, argv[2]);
+			pbnum(n - 1);
+		}
 		break;
 
 	case SYSCTYPE:
@@ -342,12 +355,18 @@ expand_builtin(const char *argv[], int argc, int td)
 		break;
 
 	case DIVRTYPE:
-		if (argc > 2 && (n = atoi(argv[2])) != 0)
-			dodiv(n);
-		else {
-			active = stdout;
-			oindex = 0;
+		if (argc > 2) {
+			n = strtonum(argv[2], INT_MIN, INT_MAX, &errstr);
+			if (errstr)
+				m4errx(1, "divert: argument is %s: %s.",
+				    errstr, argv[2]);
+			if (n != 0) {
+				dodiv(n);
+				 break;
+			}
 		}
+		active = stdout;
+		oindex = 0;
 		break;
 
 	case UNDVTYPE:



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