[gnome-builder] sysroot: escape all command parameters



commit d7f89ca31a69a69a4aa19253306995658d05ce28
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 9 17:24:30 2018 -0700

    sysroot: escape all command parameters
    
    This fixes an issue where the first parameter could be unquoted such as
    the path to a unit test in a directory with spaces.

 src/plugins/sysroot/gbp-sysroot-subprocess-launcher.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
---
diff --git a/src/plugins/sysroot/gbp-sysroot-subprocess-launcher.c 
b/src/plugins/sysroot/gbp-sysroot-subprocess-launcher.c
index 8c4203c6e..dc2b155ea 100644
--- a/src/plugins/sysroot/gbp-sysroot-subprocess-launcher.c
+++ b/src/plugins/sysroot/gbp-sysroot-subprocess-launcher.c
@@ -45,9 +45,8 @@ gbp_sysroot_subprocess_launcher_spawn (IdeSubprocessLauncher  *self,
                                        GCancellable           *cancellable,
                                        GError                 **error)
 {
-  const gchar * const *args = NULL;
+  const gchar * const *args;
   g_autoptr(GString) cmd = NULL;
-  gchar *argv = NULL;
 
   g_assert (GBP_IS_SYSROOT_SUBPROCESS_LAUNCHER (self));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
@@ -57,18 +56,15 @@ gbp_sysroot_subprocess_launcher_spawn (IdeSubprocessLauncher  *self,
   if (args[0] != NULL && g_strcmp0 (args[0], "sh") == 0 && g_strcmp0 (args[1], "-c") == 0)
     return IDE_SUBPROCESS_LAUNCHER_CLASS (gbp_sysroot_subprocess_launcher_parent_class)->spawn (self, 
cancellable, error);
 
-  argv = ide_subprocess_launcher_pop_argv (self);
-  cmd = g_string_new (argv);
-  g_free (argv);
-
-  while ((argv = ide_subprocess_launcher_pop_argv (self)) != NULL)
+  cmd = g_string_new (NULL);
+  for (guint i = 0; args[i] != NULL; i++)
     {
-      g_autofree gchar *arg = g_shell_quote(argv);
-      g_string_prepend (cmd, " ");
-      g_string_prepend (cmd, arg);
-      g_free (argv);
+      g_autofree gchar *quoted = g_shell_quote (args[i]);
+      g_string_append (cmd, quoted);
+      g_string_append_c (cmd, ' ');
     }
 
+  ide_subprocess_launcher_set_argv (self, NULL);
   ide_subprocess_launcher_push_argv (self, "sh");
   ide_subprocess_launcher_push_argv (self, "-c");
   ide_subprocess_launcher_push_argv (self, cmd->str);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]