From 07f02a83e86c4d8a4d01b2c8277a249e24674541 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Tue, 1 Sep 2020 19:30:38 +0100
Subject: [PATCH] wrap: Don't populate environment of FlatpakBwrap that will be
 merged

The default for a FlatpakBwrap object is to copy the calling
environment as a base for the environment that it will build up.
However, that's wrong if we are going to merge more than one
FlatpakBwrap together: the merged FlatpakBwrap's argv will be appended
to the destination FlatpakBwrap, but the merged envp will overwrite the
corresponding variables in the destination.

Avoid this by making sure that every time we merge two FlatpakBwrap
objects, one of them has an empty environment.

Resolves: T23422
Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 src/bwrap.c | 2 +-
 src/wrap.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/bwrap.c b/src/bwrap.c
index 747271ad1..41564beee 100644
--- a/src/bwrap.c
+++ b/src/bwrap.c
@@ -429,7 +429,7 @@ pv_bwrap_copy (FlatpakBwrap *bwrap)
    * flatpak_bwrap_append_bwrap() would steal them. */
   g_return_val_if_fail (bwrap->fds == NULL || bwrap->fds->len == 0, NULL);
 
-  ret = flatpak_bwrap_new (NULL);
+  ret = flatpak_bwrap_new (flatpak_bwrap_empty_env);
   flatpak_bwrap_append_bwrap (ret, bwrap);
   return ret;
 }
diff --git a/src/wrap.c b/src/wrap.c
index 69a9dff51..a38f86e06 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -1074,7 +1074,7 @@ main (int argc,
 
   g_debug ("Found executable directory: %s", tools_dir);
 
-  wrapped_command = flatpak_bwrap_new (NULL);
+  wrapped_command = flatpak_bwrap_new (flatpak_bwrap_empty_env);
 
   switch (opt_terminal)
     {
@@ -1447,7 +1447,7 @@ main (int argc,
   if (!flatpak_bwrap_bundle_args (bwrap, 1, -1, FALSE, error))
     goto out;
 
-  adverb_args = flatpak_bwrap_new (NULL);
+  adverb_args = flatpak_bwrap_new (flatpak_bwrap_empty_env);
 
   if (runtime != NULL)
     adverb_in_container = pv_runtime_get_adverb (runtime, adverb_args);
-- 
GitLab