Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests make(1): in lint mode, disallow dyna...



details:   https://anonhg.NetBSD.org/src/rev/2d7d87f76031
branches:  trunk
changeset: 936969:2d7d87f76031
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 03 15:43:31 2020 +0000

description:
make(1): in lint mode, disallow dynamic variable names in :@ modifier

This is an extremely obscure feature that hopefully nobody ever
considered using.

diffstat:

 distrib/sets/lists/tests/mi        |   4 +++-
 usr.bin/make/unit-tests/Makefile   |   5 ++++-
 usr.bin/make/unit-tests/lint.exp   |   4 ++++
 usr.bin/make/unit-tests/lint.mk    |  17 +++++++++++++++++
 usr.bin/make/unit-tests/modmisc.mk |   3 ++-
 usr.bin/make/var.c                 |  13 ++++++++++---
 6 files changed, 40 insertions(+), 6 deletions(-)

diffs (137 lines):

diff -r ef1ad5e867c5 -r 2d7d87f76031 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Mon Aug 03 15:08:00 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Mon Aug 03 15:43:31 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.883 2020/08/02 14:53:01 rillig Exp $
+# $NetBSD: mi,v 1.884 2020/08/03 15:43:31 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4572,6 +4572,8 @@
 ./usr/tests/usr.bin/make/unit-tests/include-main.mk    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/include-sub.mk     tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/include-subsub.mk  tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/lint.exp   tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/lint.mk    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/misc.exp   tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/misc.mk    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/moderrs.exp        tests-usr.bin-tests     compattestfile,atf
diff -r ef1ad5e867c5 -r 2d7d87f76031 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Mon Aug 03 15:08:00 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Mon Aug 03 15:43:31 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.82 2020/08/02 22:43:14 rillig Exp $
+# $NetBSD: Makefile,v 1.83 2020/08/03 15:43:32 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -57,6 +57,7 @@
 TESTS+=                hash
 TESTS+=                # impsrc        # broken by reverting POSIX changes
 TESTS+=                include-main
+TESTS+=                lint
 TESTS+=                misc
 TESTS+=                moderrs
 TESTS+=                modmatch
@@ -88,6 +89,7 @@
 ENV.counter=           -i
 ENV.envfirst=          FROM_ENV=value-from-env
 ENV.export=            -i PATH=${PATH:Q}
+ENV.lint=              -i
 ENV.varmisc=           FROM_ENV=env
 ENV.varmisc+=          FROM_ENV_BEFORE=env
 ENV.varmisc+=          FROM_ENV_AFTER=env
@@ -97,6 +99,7 @@
 FLAGS.doterror=                # none
 FLAGS.envfirst=                -e
 FLAGS.export=          -r
+FLAGS.lint=            -dL -k
 FLAGS.order=           -j1
 FLAGS.vardebug=                -k -dv FROM_CMDLINE=
 
diff -r ef1ad5e867c5 -r 2d7d87f76031 usr.bin/make/unit-tests/lint.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/lint.exp  Mon Aug 03 15:43:31 2020 +0000
@@ -0,0 +1,4 @@
+make: In the :@ modifier of "VAR", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
+y@:Q}
+xvaluey
+exit status 0
diff -r ef1ad5e867c5 -r 2d7d87f76031 usr.bin/make/unit-tests/lint.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/lint.mk   Mon Aug 03 15:43:31 2020 +0000
@@ -0,0 +1,17 @@
+# $NetBSD: lint.mk,v 1.1 2020/08/03 15:43:32 rillig Exp $
+#
+# Demonstrates stricter checks that are only enabled in the lint mode,
+# using the -dL option.
+
+# Ouch: as of 2020-08-03, make exits successfully even though the error
+# message has been issued as PARSE_FATAL.
+
+# Ouch: as of 2020-08-03, the variable is malformed and parsing stops
+# for a moment, but is continued after the wrongly-guessed end of the
+# variable, which echoes "y@:Q}".
+
+all: mod-loop-varname
+
+mod-loop-varname:
+       @echo ${VAR:Uvalue:@${:Ubar:S,b,v,}@x${var}y@:Q}
+       @echo ${VAR:Uvalue:@!@x$!y@:Q}  # surprisingly allowed
diff -r ef1ad5e867c5 -r 2d7d87f76031 usr.bin/make/unit-tests/modmisc.mk
--- a/usr.bin/make/unit-tests/modmisc.mk        Mon Aug 03 15:08:00 2020 +0000
+++ b/usr.bin/make/unit-tests/modmisc.mk        Mon Aug 03 15:43:31 2020 +0000
@@ -1,4 +1,4 @@
-# $Id: modmisc.mk,v 1.32 2020/08/01 17:26:41 rillig Exp $
+# $Id: modmisc.mk,v 1.33 2020/08/03 15:43:32 rillig Exp $
 #
 # miscellaneous modifier tests
 
@@ -161,6 +161,7 @@
 # In the :@ modifier, the name of the loop variable can even be generated
 # dynamically.  There's no practical use-case for this, and hopefully nobody
 # will ever depend on this, but technically it's possible.
+# Therefore, in -dL mode, this is forbidden, see lint.mk.
 mod-loop-varname:
        @echo :${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@:Q}:
 
diff -r ef1ad5e867c5 -r 2d7d87f76031 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Aug 03 15:08:00 2020 +0000
+++ b/usr.bin/make/var.c        Mon Aug 03 15:43:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.409 2020/08/03 15:08:00 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.410 2020/08/03 15:43:32 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.409 2020/08/03 15:08:00 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.410 2020/08/03 15:43:32 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.409 2020/08/03 15:08:00 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.410 2020/08/03 15:43:32 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1934,6 +1934,13 @@
        st->missing_delim = delim;
        return AMR_CLEANUP;
     }
+    if (DEBUG(LINT) && strchr(args.tvar, '$') != NULL) {
+       Parse_Error(PARSE_FATAL,
+                   "In the :@ modifier of \"%s\", the variable name \"%s\" "
+                   "must not contain a dollar.",
+                   st->v->name, args.tvar);
+        return AMR_CLEANUP;
+    }
 
     args.str = ParseModifierPart(pp, delim, st->eflags & ~VARE_WANTRES,
                                 st->ctxt, NULL, NULL, NULL);



Home | Main Index | Thread Index | Old Index