[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] [SV 54161] Fix second expansion of $*
From: |
Jouke Witteveen |
Subject: |
[PATCH 2/2] [SV 54161] Fix second expansion of $* |
Date: |
Sat, 12 Oct 2019 13:11:03 +0200 |
User-agent: |
Mutt/1.12.2 (2019-09-21) |
Before, this was only expanded to $(*F) in prerequisites.
---
src/implicit.c | 49 +++++++++++++++++++++++++++++++------------------
1 file changed, 31 insertions(+), 18 deletions(-)
diff --git a/src/implicit.c b/src/implicit.c
index 7bdc8ba..a887e92 100644
--- a/src/implicit.c
+++ b/src/implicit.c
@@ -220,8 +220,9 @@ pattern_search (struct file *file, int archive,
struct patdeps *deplist = xmalloc (max_deps * sizeof (struct patdeps));
struct patdeps *pat = deplist;
- /* Names of possible dependencies are constructed in this buffer. */
- char *depname = alloca (namelen + max_pattern_dep_length);
+ /* Names of possible dependencies are constructed in this buffer.
+ We replace a % by $(*F) for second expansion, increasing the length. */
+ char *depname = alloca (namelen + max_pattern_dep_length + 4);
/* The start and length of the stem of FILENAME for the current rule. */
const char *stem = 0;
@@ -479,9 +480,10 @@ pattern_search (struct file *file, int archive,
}
}
- if (stemlen > GET_PATH_MAX)
+ if (stemlen + (check_lastslash ? pathlen : 0) > GET_PATH_MAX)
{
- DBS (DB_IMPLICIT, (_("Stem too long: '%.*s'.\n"),
+ DBS (DB_IMPLICIT, (_("Stem too long: '%s%.*s'.\n"),
+ check_lastslash ? pathdir : "",
(int) stemlen, stem));
continue;
}
@@ -489,8 +491,19 @@ pattern_search (struct file *file, int archive,
DBS (DB_IMPLICIT, (_("Trying pattern rule with stem '%.*s'.\n"),
(int) stemlen, stem));
- strncpy (stem_str, stem, stemlen);
- stem_str[stemlen] = '\0';
+ if (!check_lastslash)
+ {
+ memcpy (stem_str, stem, stemlen);
+ stem_str[stemlen] = '\0';
+ }
+ else
+ {
+ /* We want to prepend the directory from
+ the original FILENAME onto the stem. */
+ memcpy (stem_str, filename, pathlen);
+ memcpy (stem_str + pathlen, stem, stemlen);
+ stem_str[pathlen + stemlen] = '\0';
+ }
/* If there are no prerequisites, then this rule matches. */
if (rule->deps == 0)
@@ -541,7 +554,7 @@ pattern_search (struct file *file, int archive,
}
memcpy (o, nptr, p - nptr);
o += p - nptr;
- memcpy (o, stem_str, stemlen);
+ memcpy (o, stem, stemlen);
o += stemlen;
strcpy (o, p + 1);
}
@@ -586,15 +599,15 @@ pattern_search (struct file *file, int archive,
continue;
}
- /* If the dependency name has %, substitute the stem. If we
- just replace % with the stem value then later, when we do
- the 2nd expansion, we will re-expand this stem value
- again. This is not good if you have certain characters
- in your stem (like $).
+ /* If the dependency name has %, substitute the filename of
+ the stem. If we just replace % with the stem value then
+ later, when we do the 2nd expansion, we will re-expand
+ this stem value again. This is not good if you have
+ certain characters in your stem (like $).
- Instead, we will replace % with $* and allow the second
- expansion to take care of it for us. This way (since $*
- is a simple variable) there won't be additional
+ Instead, we will replace % with $(*F) and allow the second
+ expansion to take care of it for us. This way (since
+ $(*F) is a simple variable) there won't be additional
re-expansion of the stem. */
p = lindex (nptr, nptr + len, '%');
@@ -607,9 +620,9 @@ pattern_search (struct file *file, int archive,
{
size_t i = p - nptr;
memcpy (depname, nptr, i);
- memcpy (depname + i, "$*", 2);
- memcpy (depname + i + 2, p + 1, len - i - 1);
- depname[len + 2 - 1] = '\0';
+ memcpy (depname + i, "$(*F)", 5);
+ memcpy (depname + i + 5, p + 1, len - i - 1);
+ depname[len + 5 - 1] = '\0';
if (check_lastslash)
add_dir = 1;
--
2.23.0
- [PATCH 2/2] [SV 54161] Fix second expansion of $*,
Jouke Witteveen <=