Module Name:    src
Committed By:   rillig
Date:           Fri Oct 23 17:53:01 UTC 2020

Modified Files:
        src/usr.bin/make/unit-tests: varname-empty.exp varname-empty.mk

Log Message:
make(1): add tests for the variable named ""


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varname-empty.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/varname-empty.mk

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/unit-tests/varname-empty.exp
diff -u src/usr.bin/make/unit-tests/varname-empty.exp:1.3 src/usr.bin/make/unit-tests/varname-empty.exp:1.4
--- src/usr.bin/make/unit-tests/varname-empty.exp:1.3	Sat Aug 22 21:22:24 2020
+++ src/usr.bin/make/unit-tests/varname-empty.exp	Fri Oct 23 17:53:01 2020
@@ -6,6 +6,8 @@ Var_Set("", "appended", ...) name expand
 Var_Set("", "", ...) name expands to empty string - ignored
 Var_Set("", "subst", ...) name expands to empty string - ignored
 Var_Set("", "shell-output", ...) name expands to empty string - ignored
+Var_Set("${:U}", "assigned indirectly", ...) name expands to empty string - ignored
+Var_Set("", "assigned", ...) name expands to empty string - ignored
 out: fallback
 out: 1 2 3
 exit status 0

Index: src/usr.bin/make/unit-tests/varname-empty.mk
diff -u src/usr.bin/make/unit-tests/varname-empty.mk:1.6 src/usr.bin/make/unit-tests/varname-empty.mk:1.7
--- src/usr.bin/make/unit-tests/varname-empty.mk:1.6	Thu Sep 24 06:03:44 2020
+++ src/usr.bin/make/unit-tests/varname-empty.mk	Fri Oct 23 17:53:01 2020
@@ -1,4 +1,4 @@
-# $NetBSD: varname-empty.mk,v 1.6 2020/09/24 06:03:44 rillig Exp $
+# $NetBSD: varname-empty.mk,v 1.7 2020/10/23 17:53:01 rillig Exp $
 #
 # Tests for the special variable with the empty name.
 #
@@ -16,22 +16,39 @@
 # The only places where a variable is assigned a value are Var_Set and
 # Var_Append, and these places protect the variable named "" from being
 # defined.  This is different from read-only variables, as that flag can
-# only apply to variables that are defined.
+# only apply to variables that are defined.  The variable named "" must
+# never be defined though.
 #
-# This is because it is heavily used in the .for loop expansion,
-# as well as to generate arbitrary strings, as in ${:Ufallback}.
+# See also:
+#	The special variables @F or ^D, in var-class-local.mk
 
 # Until 2020-08-22 it was possible to assign a value to the variable with
-# the empty name, leading to all kinds of unexpected effects.
-#
-# Before 2020-08-22, the simple assignment operator '=' had an off-by-one
-# bug that caused unrelated memory to be read in Parse_DoVar, invoking
-# undefined behavior.
+# the empty name, leading to all kinds of unexpected effects in .for loops
+# and other places that assume that ${:Ufallback} expands to "fallback".
+# The bug in Var_Set was that only expanded variables had been checked for
+# the empty name, but not the direct assignments with an empty name.
 ?=	default
 =	assigned	# undefined behavior until 2020-08-22
 +=	appended
 :=	subst
 !=	echo 'shell-output'
+.if ${:Ufallback} != "fallback"
+.  error
+.endif
+
+${:U}=	assigned indirectly
+.if ${:Ufallback} != "fallback"
+.  error
+.endif
+
+# Before 2020-08-22, the simple assignment operator '=' after an empty
+# variable name had an off-by-one bug in Parse_DoVar.  The code that was
+# supposed to "skip to operator character" started its search _after_ the
+# assignment operator, assuming that the variable name would be at least
+# one character long.  It then looked for the next occurrence of a '=', which
+# could be several lines away or not occur at all.  While looking for the
+# '=', some whitespace was nulled out, leading to out-of-bounds write.
+=	assigned	# undefined behavior until 2020-08-22
 
 # The .for loop expands the expression ${i} to ${:U1}, ${:U2} and so on.
 # This only works if the variable with the empty name is guaranteed to

Reply via email to