Module Name: src
Committed By: rillig
Date: Mon Aug 3 15:43:32 UTC 2020
Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: Makefile modmisc.mk
Added Files:
src/usr.bin/make/unit-tests: lint.exp lint.mk
Log Message:
make(1): in lint mode, disallow dynamic variable names in :@ modifier
This is an extremely obscure feature that hopefully nobody ever
considered using.
To generate a diff of this commit:
cvs rdiff -u -r1.883 -r1.884 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.409 -r1.410 src/usr.bin/make/var.c
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/lint.exp \
src/usr.bin/make/unit-tests/lint.mk
cvs rdiff -u -r1.32 -r1.33 src/usr.bin/make/unit-tests/modmisc.mk
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.883 src/distrib/sets/lists/tests/mi:1.884
--- src/distrib/sets/lists/tests/mi:1.883 Sun Aug 2 14:53:01 2020
+++ src/distrib/sets/lists/tests/mi Mon Aug 3 15:43:31 2020
@@ -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
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.409 src/usr.bin/make/var.c:1.410
--- src/usr.bin/make/var.c:1.409 Mon Aug 3 15:08:00 2020
+++ src/usr.bin/make/var.c Mon Aug 3 15:43:32 2020
@@ -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 @@ ApplyModifier_Loop(const char **pp, Appl
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);
Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.82 src/usr.bin/make/unit-tests/Makefile:1.83
--- src/usr.bin/make/unit-tests/Makefile:1.82 Sun Aug 2 22:43:14 2020
+++ src/usr.bin/make/unit-tests/Makefile Mon Aug 3 15:43:32 2020
@@ -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+= forsubst
TESTS+= hash
TESTS+= # impsrc # broken by reverting POSIX changes
TESTS+= include-main
+TESTS+= lint
TESTS+= misc
TESTS+= moderrs
TESTS+= modmatch
@@ -88,6 +89,7 @@ TESTS+= varshell
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.counter= -r -dv
FLAGS.doterror= # none
FLAGS.envfirst= -e
FLAGS.export= -r
+FLAGS.lint= -dL -k
FLAGS.order= -j1
FLAGS.vardebug= -k -dv FROM_CMDLINE=
Index: src/usr.bin/make/unit-tests/modmisc.mk
diff -u src/usr.bin/make/unit-tests/modmisc.mk:1.32 src/usr.bin/make/unit-tests/modmisc.mk:1.33
--- src/usr.bin/make/unit-tests/modmisc.mk:1.32 Sat Aug 1 17:26:41 2020
+++ src/usr.bin/make/unit-tests/modmisc.mk Mon Aug 3 15:43:32 2020
@@ -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 @@ mod-regex:
# 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}:
Added files:
Index: src/usr.bin/make/unit-tests/lint.exp
diff -u /dev/null src/usr.bin/make/unit-tests/lint.exp:1.1
--- /dev/null Mon Aug 3 15:43:32 2020
+++ src/usr.bin/make/unit-tests/lint.exp Mon Aug 3 15:43:32 2020
@@ -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
Index: src/usr.bin/make/unit-tests/lint.mk
diff -u /dev/null src/usr.bin/make/unit-tests/lint.mk:1.1
--- /dev/null Mon Aug 3 15:43:32 2020
+++ src/usr.bin/make/unit-tests/lint.mk Mon Aug 3 15:43:32 2020
@@ -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