Module Name:    src
Committed By:   rillig
Date:           Sun Apr  4 13:35:26 UTC 2021

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: var-eval-short.exp var-eval-short.mk
            varmod-loop-varname.exp varmod-loop-varname.mk
            varmod-loop-varname.out varmod-loop-varname.rawout
            varmod-loop-varname.status

Log Message:
make: disallow '$' in the variable name of the modifier ':@'

If this restriction should break any existing makefile, the author of
that makefile was probably heading for the IOMCC.


To generate a diff of this commit:
cvs rdiff -u -r1.906 -r1.907 src/usr.bin/make/var.c
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/var-eval-short.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/var-eval-short.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/varmod-loop-varname.exp \
    src/usr.bin/make/unit-tests/varmod-loop-varname.mk \
    src/usr.bin/make/unit-tests/varmod-loop-varname.out \
    src/usr.bin/make/unit-tests/varmod-loop-varname.rawout \
    src/usr.bin/make/unit-tests/varmod-loop-varname.status

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.906 src/usr.bin/make/var.c:1.907
--- src/usr.bin/make/var.c:1.906	Sun Apr  4 11:56:43 2021
+++ src/usr.bin/make/var.c	Sun Apr  4 13:35:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.906 2021/04/04 11:56:43 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.907 2021/04/04 13:35:25 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.906 2021/04/04 11:56:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.907 2021/04/04 13:35:25 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1741,9 +1741,7 @@ ModifyWord_Loop(const char *word, SepBuf
 		return;
 
 	args = data;
-	/* XXX: The variable name should not be expanded here. */
-	Var_SetExpandWithFlags(args->scope, args->tvar, word,
-	    VAR_SET_NO_EXPORT);
+	Var_SetWithFlags(args->scope, args->tvar, word, VAR_SET_NO_EXPORT);
 	(void)Var_Subst(args->str, args->scope, args->emode, &s);
 	/* TODO: handle errors */
 
@@ -2475,7 +2473,7 @@ ApplyModifier_Loop(const char **pp, ModC
 	res = ParseModifierPart(pp, '@', VARE_PARSE_ONLY, ch, &args.tvar);
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
-	if (opts.strict && strchr(args.tvar, '$') != NULL) {
+	if (strchr(args.tvar, '$') != NULL) {
 		Parse_Error(PARSE_FATAL,
 		    "In the :@ modifier of \"%s\", the variable name \"%s\" "
 		    "must not contain a dollar.",
@@ -2496,11 +2494,7 @@ ApplyModifier_Loop(const char **pp, ModC
 	ModifyWords(ch, ModifyWord_Loop, &args, ch->oneBigWord);
 	ch->sep = prev_sep;
 	/* XXX: Consider restoring the previous variable instead of deleting. */
-	/*
-	 * XXX: The variable name should not be expanded here, see
-	 * ModifyWord_Loop.
-	 */
-	Var_DeleteExpand(expr->scope, args.tvar);
+	Var_Delete(expr->scope, args.tvar);
 
 done:
 	free(args.tvar);

Index: src/usr.bin/make/unit-tests/var-eval-short.exp
diff -u src/usr.bin/make/unit-tests/var-eval-short.exp:1.10 src/usr.bin/make/unit-tests/var-eval-short.exp:1.11
--- src/usr.bin/make/unit-tests/var-eval-short.exp:1.10	Sun Apr  4 10:13:09 2021
+++ src/usr.bin/make/unit-tests/var-eval-short.exp	Sun Apr  4 13:35:26 2021
@@ -1,14 +1,16 @@
-make: "var-eval-short.mk" line 77: Invalid time value: ${FAIL}}
-make: "var-eval-short.mk" line 77: Malformed conditional (0 && ${:Uword:gmtime=${FAIL}})
-make: "var-eval-short.mk" line 91: Invalid time value: ${FAIL}}
-make: "var-eval-short.mk" line 91: Malformed conditional (0 && ${:Uword:localtime=${FAIL}})
+make: "var-eval-short.mk" line 41: In the :@ modifier of "", the variable name "${FAIL}" must not contain a dollar.
+make: "var-eval-short.mk" line 41: Malformed conditional (0 && ${:Uword:@${FAIL}@expr@})
+make: "var-eval-short.mk" line 79: Invalid time value: ${FAIL}}
+make: "var-eval-short.mk" line 79: Malformed conditional (0 && ${:Uword:gmtime=${FAIL}})
+make: "var-eval-short.mk" line 93: Invalid time value: ${FAIL}}
+make: "var-eval-short.mk" line 93: Malformed conditional (0 && ${:Uword:localtime=${FAIL}})
 CondParser_Eval: 0 && ${0:?${FAIL}then:${FAIL}else}
 Var_Parse: ${0:?${FAIL}then:${FAIL}else} (parse-only)
 Applying ${0:?...} to "" (parse-only, undefined)
 Modifier part: "${FAIL}then"
 Modifier part: "${FAIL}else"
 Result of ${0:?${FAIL}then:${FAIL}else} is "" (parse-only, defined)
-ParseReadLine (156): 'DEFINED=	defined'
+ParseReadLine (158): 'DEFINED=	defined'
 Global:DEFINED = defined
 CondParser_Eval: 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else}
 Var_Parse: ${DEFINED:L:?${FAIL}then:${FAIL}else} (parse-only)
@@ -18,7 +20,7 @@ Applying ${DEFINED:?...} to "defined" (p
 Modifier part: "${FAIL}then"
 Modifier part: "${FAIL}else"
 Result of ${DEFINED:?${FAIL}then:${FAIL}else} is "defined" (parse-only, regular)
-ParseReadLine (159): '.MAKEFLAGS: -d0'
+ParseReadLine (161): '.MAKEFLAGS: -d0'
 ParseDependency(.MAKEFLAGS: -d0)
 Global:.MAKEFLAGS =  -r -k -d cpv -d
 Global:.MAKEFLAGS =  -r -k -d cpv -d 0

Index: src/usr.bin/make/unit-tests/var-eval-short.mk
diff -u src/usr.bin/make/unit-tests/var-eval-short.mk:1.4 src/usr.bin/make/unit-tests/var-eval-short.mk:1.5
--- src/usr.bin/make/unit-tests/var-eval-short.mk:1.4	Sun Mar 14 20:41:39 2021
+++ src/usr.bin/make/unit-tests/var-eval-short.mk	Sun Apr  4 13:35:26 2021
@@ -1,4 +1,4 @@
-# $NetBSD: var-eval-short.mk,v 1.4 2021/03/14 20:41:39 rillig Exp $
+# $NetBSD: var-eval-short.mk,v 1.5 2021/04/04 13:35:26 rillig Exp $
 #
 # Tests for each variable modifier to ensure that they only do the minimum
 # necessary computations.  If the result of the expression is not needed, they
@@ -34,8 +34,10 @@ FAIL=	${:!echo unexpected 1>&2!}
 .if 0 && ${0:?${FAIL}:${FAIL}}
 .endif
 
-# Before var.c,v 1.870 from 2021-03-14, the expression ${FAIL} was evaluated
+# Before var.c 1.870 from 2021-03-14, the expression ${FAIL} was evaluated
 # after the loop, when undefining the temporary global loop variable.
+# Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the
+# variable name.
 .if 0 && ${:Uword:@${FAIL}@expr@}
 .endif
 

Index: src/usr.bin/make/unit-tests/varmod-loop-varname.exp
diff -u src/usr.bin/make/unit-tests/varmod-loop-varname.exp:1.1 src/usr.bin/make/unit-tests/varmod-loop-varname.exp:1.2
--- src/usr.bin/make/unit-tests/varmod-loop-varname.exp:1.1	Sun Apr  4 13:20:52 2021
+++ src/usr.bin/make/unit-tests/varmod-loop-varname.exp	Sun Apr  4 13:35:26 2021
@@ -1 +1,11 @@
-exit status 0
+make: "varmod-loop-varname.mk" line 13: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 13: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+")
+make: "varmod-loop-varname.mk" line 80: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 80: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)")
+make: "varmod-loop-varname.mk" line 85: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 85: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()")
+make: "varmod-loop-varname.mk" line 90: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 90: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()")
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
Index: src/usr.bin/make/unit-tests/varmod-loop-varname.mk
diff -u src/usr.bin/make/unit-tests/varmod-loop-varname.mk:1.1 src/usr.bin/make/unit-tests/varmod-loop-varname.mk:1.2
--- src/usr.bin/make/unit-tests/varmod-loop-varname.mk:1.1	Sun Apr  4 13:20:52 2021
+++ src/usr.bin/make/unit-tests/varmod-loop-varname.mk	Sun Apr  4 13:35:26 2021
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-loop-varname.mk,v 1.1 2021/04/04 13:20:52 rillig Exp $
+# $NetBSD: varmod-loop-varname.mk,v 1.2 2021/04/04 13:35:26 rillig Exp $
 #
 # Tests for the first part of the variable modifier ':@var@...@', which
 # contains the variable name to use during the loop.
@@ -6,10 +6,10 @@
 .MAKE.SAVE_DOLLARS=	yes
 
 
-# In the :@ modifier, the name of the loop variable can 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.
+# Before 2021-04-04, the name of the loop variable could be generated
+# dynamically.  There was no practical use-case for this.
+# Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the
+# variable name.
 .if ${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+"
 .  error
 .endif
@@ -75,14 +75,22 @@ RES3=		3
 # Until 2020-07-20, the variable name of the :@ modifier could end with one
 # or two dollar signs, which were silently ignored.
 # There's no point in allowing a dollar sign in that position.
+# Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the
+# variable name.
 .if ${1 2 3:L:@v$@($v)@} != "(1) (2) (3)"
 .  error
+.else
+.  error
 .endif
 .if ${1 2 3:L:@v$$@($v)@} != "() () ()"
 .  error
+.else
+.  error
 .endif
 .if ${1 2 3:L:@v$$$@($v)@} != "() () ()"
 .  error
+.else
+.  error
 .endif
 
 
Index: src/usr.bin/make/unit-tests/varmod-loop-varname.out
diff -u src/usr.bin/make/unit-tests/varmod-loop-varname.out:1.1 src/usr.bin/make/unit-tests/varmod-loop-varname.out:1.2
--- src/usr.bin/make/unit-tests/varmod-loop-varname.out:1.1	Sun Apr  4 13:20:52 2021
+++ src/usr.bin/make/unit-tests/varmod-loop-varname.out	Sun Apr  4 13:35:26 2021
@@ -1 +1,11 @@
-exit status 0
+make: "varmod-loop-varname.mk" line 13: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 13: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+")
+make: "varmod-loop-varname.mk" line 80: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 80: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)")
+make: "varmod-loop-varname.mk" line 85: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 85: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()")
+make: "varmod-loop-varname.mk" line 90: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 90: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()")
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
Index: src/usr.bin/make/unit-tests/varmod-loop-varname.rawout
diff -u src/usr.bin/make/unit-tests/varmod-loop-varname.rawout:1.1 src/usr.bin/make/unit-tests/varmod-loop-varname.rawout:1.2
--- src/usr.bin/make/unit-tests/varmod-loop-varname.rawout:1.1	Sun Apr  4 13:20:52 2021
+++ src/usr.bin/make/unit-tests/varmod-loop-varname.rawout	Sun Apr  4 13:35:26 2021
@@ -0,0 +1,10 @@
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 13: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 13: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+")
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 80: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar.
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 80: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)")
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 85: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar.
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 85: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()")
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 90: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar.
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 90: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()")
+make: Fatal errors encountered -- cannot continue
+make: stopped in /home/rillig/proj/src/usr.bin/make/unit-tests
Index: src/usr.bin/make/unit-tests/varmod-loop-varname.status
diff -u src/usr.bin/make/unit-tests/varmod-loop-varname.status:1.1 src/usr.bin/make/unit-tests/varmod-loop-varname.status:1.2
--- src/usr.bin/make/unit-tests/varmod-loop-varname.status:1.1	Sun Apr  4 13:20:52 2021
+++ src/usr.bin/make/unit-tests/varmod-loop-varname.status	Sun Apr  4 13:35:26 2021
@@ -1 +1 @@
-0
+1

Reply via email to