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): fix assignment to .CURDIR via the shel...



details:   https://anonhg.NetBSD.org/src/rev/70810e673c88
branches:  trunk
changeset: 976829:70810e673c88
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Oct 04 21:53:28 2020 +0000

description:
make(1): fix assignment to .CURDIR via the shell assignment operator

This is probably an edge case that nobody will ever stumble upon, since
.CURDIR is usually regarded as a read-only variable.

The other variable that is affected by this code path is .MAKE.EXPORTED,
and for this variable as well, it would be unusual to assign it a value
from a shell command.

diffstat:

 usr.bin/make/parse.c                          |  37 ++++++++++++--------------
 usr.bin/make/unit-tests/varname-dot-curdir.mk |  16 ++++++-----
 2 files changed, 26 insertions(+), 27 deletions(-)

diffs (99 lines):

diff -r c033ec4b6a13 -r 70810e673c88 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sun Oct 04 21:41:44 2020 +0000
+++ b/usr.bin/make/parse.c      Sun Oct 04 21:53:28 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.361 2020/10/04 21:41:44 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.362 2020/10/04 21:53:28 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.361 2020/10/04 21:41:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.362 2020/10/04 21:53:28 rillig Exp $");
 
 /* types and constants */
 
@@ -1850,29 +1850,26 @@
 
        Var_Set(name, avalue, ctxt);
     } else if (type == VAR_SHELL) {
-       char *res;
-       const char *error;
+        const char *cmd, *errfmt;
+        char *cmdOut;
+        void *cmd_freeIt = NULL;
 
-       if (strchr(uvalue, '$') != NULL) {
-           char *evalue;
-           /*
-            * There's a dollar sign in the command, so perform variable
-            * expansion on the whole thing. The resulting string will need
-            * freeing when we're done.
-            */
-           (void)Var_Subst(uvalue, VAR_CMD, VARE_UNDEFERR|VARE_WANTRES,
-                           &evalue);
+       cmd = uvalue;
+       if (strchr(cmd, '$') != NULL) {
+           char *ecmd;
+           (void)Var_Subst(cmd, VAR_CMD, VARE_UNDEFERR|VARE_WANTRES, &ecmd);
            /* TODO: handle errors */
-           avalue = evalue;
-           avalue_freeIt = evalue;
+           cmd = cmd_freeIt = ecmd;
        }
 
-       res = Cmd_Exec(avalue, &error);
-       Var_Set(name, res, ctxt);
-       free(res);
+       cmdOut = Cmd_Exec(cmd, &errfmt);
+       Var_Set(name, cmdOut, ctxt);
+       avalue = avalue_freeIt = cmdOut;
 
-       if (error)
-           Parse_Error(PARSE_WARNING, error, avalue);
+       if (errfmt)
+           Parse_Error(PARSE_WARNING, errfmt, cmd);
+
+       free(cmd_freeIt);
     } else {
        if (type == VAR_DEFAULT && Var_Exists(var->varname, ctxt)) {
            *out_avalue_freeIt = NULL;
diff -r c033ec4b6a13 -r 70810e673c88 usr.bin/make/unit-tests/varname-dot-curdir.mk
--- a/usr.bin/make/unit-tests/varname-dot-curdir.mk     Sun Oct 04 21:41:44 2020 +0000
+++ b/usr.bin/make/unit-tests/varname-dot-curdir.mk     Sun Oct 04 21:53:28 2020 +0000
@@ -1,15 +1,17 @@
-# $NetBSD: varname-dot-curdir.mk,v 1.3 2020/10/04 20:06:48 rillig Exp $
+# $NetBSD: varname-dot-curdir.mk,v 1.4 2020/10/04 21:53:28 rillig Exp $
 #
 # Tests for the special .CURDIR variable.
 
 # TODO: Implementation
 
-# As of 2020-10-04, assigning the result of a shell command to .CURDIR tries
-# to add the shell command to the .PATH instead of the output of the shell
-# command.  Since "echo /" does not exist, the .PATH is left unmodified.
-# See Parse_DoVar at the very bottom.
+# Until 2020-10-04, assigning the result of a shell assignment to .CURDIR
+# tried to add the shell command ("echo /") to the .PATH instead of the
+# output of the shell command ("/").  Since "echo /" does not exist, the
+# .PATH was left unmodified.  See VarAssign_Eval.
+#
+# Since 2020-10-04, the output of the shell command is added to .PATH.
 .CURDIR!=      echo /
-.if ${.PATH:M/}
+.if ${.PATH:M/} != "/"
 .  error
 .endif
 
@@ -17,7 +19,7 @@
 # Appending to .CURDIR does not make sense, therefore it doesn't matter that
 # this code path is buggy as well.
 .CURDIR=       /
-.if !${.PATH:M/}
+.if ${.PATH:M/} != "/"
 .  error
 .endif
 



Home | Main Index | Thread Index | Old Index