From 0fc517c113b55abe3a66e27c006aad4e822efd07 Mon Sep 17 00:00:00 2001 From: rillig Date: Sun, 14 Mar 2021 17:27:27 +0000 Subject: [PATCH] make: do not expand the variable name in the ':_' modifier This edge case had been so obscure that even discovering this takes quite some time and requires reading the source code of make. The manual page doesn't document whether the variable name is expanded or not, it doesn't even give an example. When this obscure modifier was initially added in var.c 1.210 from 2017-01-30, Var_Set always expanded the variable name once, and there was no way around it. Therefore this expansion has probably been unintentional. --- usr.bin/make/unit-tests/varmod-remember.mk | 7 +++++-- usr.bin/make/var.c | 12 +++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/usr.bin/make/unit-tests/varmod-remember.mk b/usr.bin/make/unit-tests/varmod-remember.mk index a5bfe6823858..403811759672 100644 --- a/usr.bin/make/unit-tests/varmod-remember.mk +++ b/usr.bin/make/unit-tests/varmod-remember.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-remember.mk,v 1.5 2021/03/14 17:14:15 rillig Exp $ +# $NetBSD: varmod-remember.mk,v 1.6 2021/03/14 17:27:27 rillig Exp $ # # Tests for the :_ modifier, which saves the current variable value # in the _ variable or another, to be used later again. @@ -22,10 +22,13 @@ # oversight than an intended feature. The variable name stops at the first # '}' or ')' and thus cannot use the usual form ${VARNAME} of long variable # names. +# +# Because of all these edge-casey conditions, this "feature" has been removed +# in var.c 1.867 from 2021-03-14. S= INDIRECT_VARNAME .if ${value:L:@var@${var:_=$S}@} != "value" . error -.elif ${INDIRECT_VARNAME} != "value" +.elif defined(INDIRECT_VARNAME) . error .endif diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 27bfafd79282..479499e26c2f 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.866 2021/03/14 16:43:30 rillig Exp $ */ +/* $NetBSD: var.c,v 1.867 2021/03/14 17:27:27 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -140,7 +140,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.866 2021/03/14 16:43:30 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.867 2021/03/14 17:27:27 rillig Exp $"); typedef enum VarFlags { VFL_NONE = 0, @@ -3433,13 +3433,7 @@ ApplyModifier_Remember(const char **pp, ApplyModifiersState *st) if (expr->eflags & VARE_WANTRES) { char *name = bmake_strldup(mod + 2, n); - - /* - * FIXME: do not expand the variable name here; it - * would only work for single-character variable names - * anyway. - */ - Var_SetExpand(expr->scope, name, expr->value.str); + Var_Set(expr->scope, name, expr->value.str); free(name); } } else {