diff options
| author | rillig <rillig@NetBSD.org> | 2020-10-04 21:53:28 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2020-10-04 21:53:28 +0000 |
| commit | 2ef9e8d68e84f34454ed9fc16adecc49abc33652 (patch) | |
| tree | e467dda8f864b0d699f88478d3a6fb406e65fe96 /usr.bin/make/parse.c | |
| parent | 9dc11cc11024acb7ed072ff4394a848d0218dc43 (diff) | |
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 (limited to 'usr.bin/make/parse.c')
| -rw-r--r-- | usr.bin/make/parse.c | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c index 0a2cee7a991..d5bf6f5b5e4 100644 --- a/usr.bin/make/parse.c +++ b/usr.bin/make/parse.c @@ -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 @@ VarAssign_Eval(VarAssign *var, GNode *ctxt, Var_Set(name, avalue, ctxt); } else if (type == VAR_SHELL) { - char *res; - const char *error; - - 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); + const char *cmd, *errfmt; + char *cmdOut; + void *cmd_freeIt = NULL; + + 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 (errfmt) + Parse_Error(PARSE_WARNING, errfmt, cmd); - if (error) - Parse_Error(PARSE_WARNING, error, avalue); + free(cmd_freeIt); } else { if (type == VAR_DEFAULT && Var_Exists(var->varname, ctxt)) { *out_avalue_freeIt = NULL; |
