Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): prevent assignment to the variable wit...



details:   https://anonhg.NetBSD.org/src/rev/bc415d0e2735
branches:  trunk
changeset: 975170:bc415d0e2735
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 22 20:31:50 2020 +0000

description:
make(1): prevent assignment to the variable with the empty name

diffstat:

 usr.bin/make/unit-tests/varname-empty.exp |   4 ++--
 usr.bin/make/unit-tests/varname-empty.mk  |   5 +++--
 usr.bin/make/var.c                        |  24 ++++++++++++------------
 3 files changed, 17 insertions(+), 16 deletions(-)

diffs (87 lines):

diff -r 04ab9a0b736f -r bc415d0e2735 usr.bin/make/unit-tests/varname-empty.exp
--- a/usr.bin/make/unit-tests/varname-empty.exp Sat Aug 22 20:23:14 2020 +0000
+++ b/usr.bin/make/unit-tests/varname-empty.exp Sat Aug 22 20:31:50 2020 +0000
@@ -1,3 +1,3 @@
-value
-value value value
+fallback
+1 2 3
 exit status 0
diff -r 04ab9a0b736f -r bc415d0e2735 usr.bin/make/unit-tests/varname-empty.mk
--- a/usr.bin/make/unit-tests/varname-empty.mk  Sat Aug 22 20:23:14 2020 +0000
+++ b/usr.bin/make/unit-tests/varname-empty.mk  Sat Aug 22 20:31:50 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varname-empty.mk,v 1.1 2020/08/22 20:23:14 rillig Exp $
+# $NetBSD: varname-empty.mk,v 1.2 2020/08/22 20:31:50 rillig Exp $
 #
 # Tests for the special variable with the empty name.
 #
@@ -6,7 +6,8 @@
 # This is because it is heavily used in the .for loop expansion,
 # as well as to generate arbitrary strings, as in ${:Ufallback}.
 
-# Oops.
+# 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.
 !=     echo 'value'
 
 # The .for loop expands the expression ${i} to ${:U1}, ${:U2} and so on.
diff -r 04ab9a0b736f -r bc415d0e2735 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Aug 22 20:23:14 2020 +0000
+++ b/usr.bin/make/var.c        Sat Aug 22 20:31:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.457 2020/08/22 19:30:58 sjg Exp $    */
+/*     $NetBSD: var.c,v 1.458 2020/08/22 20:31:50 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.457 2020/08/22 19:30:58 sjg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.458 2020/08/22 20:31:50 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.457 2020/08/22 19:30:58 sjg Exp $");
+__RCSID("$NetBSD: var.c,v 1.458 2020/08/22 20:31:50 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -778,6 +778,7 @@
 Var_Set_with_flags(const char *name, const char *val, GNode *ctxt,
                   VarSet_Flags flags)
 {
+    const char *unexpanded_name = name;
     char *name_freeIt = NULL;
     Var *v;
 
@@ -786,16 +787,15 @@
      * here will override anything in a lower context, so there's not much
      * point in searching them all just to save a bit of memory...
      */
-    if (strchr(name, '$') != NULL) {
-       const char *unexpanded_name = name;
+    if (strchr(name, '$') != NULL)
        name = name_freeIt = Var_Subst(name, ctxt, VARE_WANTRES);
-       if (name[0] == '\0') {
-           VAR_DEBUG("Var_Set(\"%s\", \"%s\", ...) "
-                     "name expands to empty string - ignored\n",
-                     unexpanded_name, val);
-           free(name_freeIt);
-           return;
-       }
+
+    if (name[0] == '\0') {
+       VAR_DEBUG("Var_Set(\"%s\", \"%s\", ...) "
+                 "name expands to empty string - ignored\n",
+                 unexpanded_name, val);
+       free(name_freeIt);
+       return;
     }
 
     if (ctxt == VAR_GLOBAL) {



Home | Main Index | Thread Index | Old Index