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: fix crash on .undef of an environment var...



details:   https://anonhg.NetBSD.org/src/rev/a7f5cf0f6c81
branches:  trunk
changeset: 364460:a7f5cf0f6c81
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Mar 26 12:44:57 2022 +0000

description:
make: fix crash on .undef of an environment variable (since 2020-10-06)

diffstat:

 usr.bin/make/unit-tests/Makefile           |   3 ++-
 usr.bin/make/unit-tests/directive-undef.mk |  14 +++++++++++++-
 usr.bin/make/var.c                         |  24 +++++++++---------------
 3 files changed, 24 insertions(+), 17 deletions(-)

diffs (89 lines):

diff -r 63aa1296c473 -r a7f5cf0f6c81 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Sat Mar 26 06:49:27 2022 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Sat Mar 26 12:44:57 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.310 2022/03/25 22:38:39 rillig Exp $
+# $NetBSD: Makefile,v 1.311 2022/03/26 12:44:57 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -467,6 +467,7 @@
 # Additional environment variables for some of the tests.
 # The base environment is -i PATH="$PATH".
 ENV.depsrc-optional+=   TZ=UTC
+ENV.directive-undef=   ENV_VAR=env-value
 ENV.envfirst=          FROM_ENV=value-from-env
 ENV.varmisc=           FROM_ENV=env
 ENV.varmisc+=          FROM_ENV_BEFORE=env
diff -r 63aa1296c473 -r a7f5cf0f6c81 usr.bin/make/unit-tests/directive-undef.mk
--- a/usr.bin/make/unit-tests/directive-undef.mk        Sat Mar 26 06:49:27 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-undef.mk        Sat Mar 26 12:44:57 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: directive-undef.mk,v 1.11 2022/03/25 23:03:47 rillig Exp $
+# $NetBSD: directive-undef.mk,v 1.12 2022/03/26 12:44:57 rillig Exp $
 #
 # Tests for the .undef directive.
 #
@@ -130,4 +130,16 @@
 .endif
 
 
+# Since var.c 1.570 from 2020-10-06 and before var.c 1.1014 from 2022-03-26,
+# make ran into an assertion failure when trying to undefine a variable that
+# was based on an environment variable.
+.if ${ENV_VAR} != "env-value"  # see ./Makefile, ENV.directive-undef
+.  error
+.endif
+ENV_VAR+=      appended        # moves the short-lived variable to the
+                               # global scope
+.undef ENV_VAR                 # removes the variable from both the global
+                               # scope and from the environment
+
+
 all:
diff -r 63aa1296c473 -r a7f5cf0f6c81 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Mar 26 06:49:27 2022 +0000
+++ b/usr.bin/make/var.c        Sat Mar 26 12:44:57 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.1013 2022/03/03 19:52:41 rillig Exp $        */
+/*     $NetBSD: var.c,v 1.1014 2022/03/26 12:44:57 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1013 2022/03/03 19:52:41 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1014 2022/03/26 12:44:57 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1088,20 +1088,14 @@
                DEBUG3(VAR, "%s: %s = %s\n", scope->name, name, v->val.data);
 
                if (v->fromEnvironment) {
-                       /*
-                        * The variable originally came from the environment.
-                        * Install it in the global scope (we could place it
-                        * in the environment, but then we should provide a
-                        * way to export other variables...)
-                        */
+                       /* See VarAdd. */
+                       HashEntry *he =
+                           HashTable_CreateEntry(&scope->vars, name, NULL);
+                       HashEntry_Set(he, v);
+                       FStr_Done(&v->name);
+                       v->name = FStr_InitRefer(/* aliased to */ he->key);
+                       v->shortLived = false;
                        v->fromEnvironment = false;
-                       v->shortLived = false;
-                       /*
-                        * This is the only place where a variable is
-                        * created in a scope, where v->name does not alias
-                        * scope->vars->key.
-                        */
-                       HashTable_Set(&scope->vars, name, v);
                }
        }
 }



Home | Main Index | Thread Index | Old Index