From 5dc97e2eeb5f2c3173f0227ef8d0d64e10cbc9cd Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 9 Jun 2022 15:40:44 +0300 Subject: Fix crashing in up_negotiate_configuration() --- bpkg/package-configuration.cxx | 9 +++++++-- bpkg/package-configuration.hxx | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bpkg/package-configuration.cxx b/bpkg/package-configuration.cxx index 6ec2ea3..624de18 100644 --- a/bpkg/package-configuration.cxx +++ b/bpkg/package-configuration.cxx @@ -130,10 +130,15 @@ namespace bpkg if (da.prefer || cfg.empty ()) depc.reload_defaults (cfg); - - depc_cfgs.push_back (cfg); } + // Note that we need to collect the dependency configurations as a + // separate loop so that the stored references are not invalidated by + // operator[] (which is really a push_back() into a vector). + // + for (package_skeleton& depc: depcs) + depc_cfgs.push_back (cfgs[depc.key]); + // Step 2: execute the prefer/accept or requires clauses. // if (!(da.require diff --git a/bpkg/package-configuration.hxx b/bpkg/package-configuration.hxx index 80ededb..d6fc989 100644 --- a/bpkg/package-configuration.hxx +++ b/bpkg/package-configuration.hxx @@ -102,6 +102,8 @@ namespace bpkg class package_configurations: public small_vector { public: + // Note: may invalidate references. + // package_configuration& operator[] (const package_key& p) { -- cgit v1.1