From c5504c6342ae0c77286720faeef5c1b7302771fc Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Thu, 8 Aug 2019 14:19:59 +0100
Subject: [PATCH] wrap: Bundle command-line options for bwrap into a memfd

This avoids overrunning command-line length limits if we have a lot of
arguments.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 src/wrap.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/wrap.c b/src/wrap.c
index c21c86cb3..8bdc1918a 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -2040,15 +2040,30 @@ main (int argc,
         }
     }
 
+  if (opt_verbose)
+    {
+      g_message ("%s options before bundling:", bwrap_executable);
+
+      for (i = 0; i < bwrap->argv->len; i++)
+        {
+          g_autofree gchar *quoted = NULL;
+
+          quoted = g_shell_quote (g_ptr_array_index (bwrap->argv, i));
+          g_message ("\t%s", quoted);
+        }
+    }
+
+  if (!flatpak_bwrap_bundle_args (bwrap, 1, -1, FALSE, error))
+    goto out;
+
   g_debug ("Adding wrapped command...");
   flatpak_bwrap_append_args (bwrap, wrapped_command->argv);
-  flatpak_bwrap_finish (bwrap);
 
   if (opt_verbose)
     {
-      g_message ("%s options:", bwrap_executable);
+      g_message ("Final %s options:", bwrap_executable);
 
-      for (i = 0; i < bwrap->argv->len - 1; i++)
+      for (i = 0; i < bwrap->argv->len; i++)
         {
           g_autofree gchar *quoted = NULL;
 
@@ -2067,6 +2082,8 @@ main (int argc,
         }
     }
 
+  flatpak_bwrap_finish (bwrap);
+
   /* flatpak_bwrap_finish did this */
   g_assert (g_ptr_array_index (bwrap->argv, bwrap->argv->len - 1) == NULL);
 
-- 
GitLab