diff options
author | jmallett <jmallett@FreeBSD.org> | 2002-06-19 17:23:08 +0000 |
---|---|---|
committer | jmallett <jmallett@FreeBSD.org> | 2002-06-19 17:23:08 +0000 |
commit | 4586b0f32343e920637042c5f7f5a4a22a86e000 (patch) | |
tree | ccc93ff248910525f5ed311d3b0e4cd4599bef00 /usr.bin/make | |
parent | b8430132a85fde394ea3dae8a0a44ed6f43623a5 (diff) | |
download | FreeBSD-src-4586b0f32343e920637042c5f7f5a4a22a86e000.zip FreeBSD-src-4586b0f32343e920637042c5f7f5a4a22a86e000.tar.gz |
Possibly expand the variable name's embedded variables before using it, as
seen (somewhat) in NetBSD. This catches a few extra recursion cases that
could be hidden by expanding a NIL variable causing an existing variable to
be returned (which caused infinite looping and climbing memory usage in at
least one case).
Obtained from: NetBSD (in principle)
Diffstat (limited to 'usr.bin/make')
-rw-r--r-- | usr.bin/make/var.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index e5e09ea..f7e5e47 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -167,6 +167,7 @@ typedef struct { } VarREPattern; static int VarCmp(void *, void *); +static void VarPossiblyExpand(char **, GNode *); static Var *VarFind(char *, GNode *, int); static void VarAdd(char *, char *, GNode *); static void VarDelete(void *); @@ -212,6 +213,27 @@ VarCmp (v, name) /*- *----------------------------------------------------------------------- + * VarPossiblyExpand -- + * Expand a variable name's embedded variables in the given context. + * + * Results: + * The string pointed to by `name' may change. + * + * Side Effects: + * None. + *----------------------------------------------------------------------- + */ +static void +VarPossiblyExpand(name, ctxt) + char **name; + GNode *ctxt; +{ + if (strchr(*name, '$') != NULL) + *name = Var_Subst(NULL, *name, ctxt, 0); +} + +/*- + *----------------------------------------------------------------------- * VarFind -- * Find the given variable in the given context and any other contexts * indicated. @@ -471,6 +493,7 @@ Var_Set (name, val, ctxt) * 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... */ + VarPossiblyExpand(&name, ctxt); v = VarFind (name, ctxt, 0); if (v == (Var *) NULL) { VarAdd (name, val, ctxt); @@ -521,6 +544,7 @@ Var_Append (name, val, ctxt) { Var *v; + VarPossiblyExpand(&name, ctxt); v = VarFind (name, ctxt, (ctxt == VAR_GLOBAL) ? FIND_ENV : 0); if (v == (Var *) NULL) { @@ -567,6 +591,7 @@ Var_Exists(name, ctxt) { Var *v; + VarPossiblyExpand(&name, ctxt); v = VarFind(name, ctxt, FIND_CMD|FIND_GLOBAL|FIND_ENV); if (v == (Var *)NULL) { @@ -599,6 +624,7 @@ Var_Value (name, ctxt, frp) { Var *v; + VarPossiblyExpand(&name, ctxt); v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); *frp = NULL; if (v != (Var *) NULL) { |