summaryrefslogtreecommitdiff
path: root/src/file.c
diff options
context:
space:
mode:
authorSergei Trofimovich <siarheit@google.com>2022-09-11 21:28:59 +0100
committerPaul Smith <psmith@gnu.org>2022-09-12 01:05:31 -0400
commitca4234c4b550618df2194e0617c43bb12524f820 (patch)
tree5942432a68bbce2e60ef8623c729ca57762eb98d /src/file.c
parent257b82ac1ff8ba13428b93ca774d44d1c2febb61 (diff)
downloadmake-git-ca4234c4b550618df2194e0617c43bb12524f820.tar.gz
[SV 63047] Fix shuffle of SECONDEXPANSION prerequisites
Commit 07eea3aa4 `make --shuffle` prevented shuffling prerequisites that use .SECONDEXPANSION, since shuffle happens before expansion. This has two problems: 1. No shuffling happens for such prerequisites. 2. Use-after-free when outdated '->shuf' links are used. Add a reshuffle into expansion phase right after dependency changes. * src/file.c (expand_deps): Add reshuffle if dependencies change. * src/shuffle.c (identity_shuffle_array): Fix comment typo. * tests/scripts/options/shuffle: Add new SECONDEXPANSION test.
Diffstat (limited to 'src/file.c')
-rw-r--r--src/file.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/file.c b/src/file.c
index 7596ff10..2cb013ef 100644
--- a/src/file.c
+++ b/src/file.c
@@ -25,6 +25,7 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
#include "variable.h"
#include "debug.h"
#include "hash.h"
+#include "shuffle.h"
/* Remember whether snap_deps has been invoked: we need this to be sure we
@@ -576,6 +577,7 @@ expand_deps (struct file *f)
struct dep **dp;
const char *fstem;
int initialized = 0;
+ int changed_dep = 0;
if (f->snapped)
return;
@@ -664,6 +666,7 @@ expand_deps (struct file *f)
if (new == 0)
{
*dp = d->next;
+ changed_dep = 1;
free_dep (d);
d = *dp;
continue;
@@ -672,6 +675,7 @@ expand_deps (struct file *f)
/* Add newly parsed prerequisites. */
fstem = d->stem;
next = d->next;
+ changed_dep = 1;
free_dep (d);
*dp = new;
for (dp = &new, d = new; d != 0; dp = &d->next, d = d->next)
@@ -688,6 +692,12 @@ expand_deps (struct file *f)
*dp = next;
d = *dp;
}
+
+ /* Shuffle mode assumes '->next' and '->shuf' links both traverse the same
+ dependencies (in different sequences). Regenerate '->shuf' so we don't
+ refer to stale data. */
+ if (changed_dep)
+ shuffle_deps_recursive (f->deps);
}
/* Add extra prereqs to the file in question. */