[gnome-builder] flatpak: Fix use-after-free



commit 7a8faccad442a2df4a5bc50a470e5f9908fe0861
Author: Matthew Leeds <mwleeds protonmail com>
Date:   Tue May 16 22:48:17 2017 -0500

    flatpak: Fix use-after-free
    
    We need to add a comma to the previous line to keep the JSON valid, but
    without using the pointer after it has been freed.

 .../flatpak/gbp-flatpak-configuration-provider.c   |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/plugins/flatpak/gbp-flatpak-configuration-provider.c 
b/plugins/flatpak/gbp-flatpak-configuration-provider.c
index 8fb668a..3a4d493 100644
--- a/plugins/flatpak/gbp-flatpak-configuration-provider.c
+++ b/plugins/flatpak/gbp-flatpak-configuration-provider.c
@@ -398,9 +398,12 @@ gbp_flatpak_configuration_provider_save_worker (GTask        *task,
                   if (!config_opts_replaced && new_config_opts != NULL)
                     {
                       gchar *previous_line;
+                      gchar *new_line;
 
-                      previous_line = (gchar *)g_ptr_array_remove_index (new_lines, new_lines->len - 1);
-                      g_ptr_array_add (new_lines, g_strdup_printf ("%s,", previous_line));
+                      previous_line = (gchar *)g_ptr_array_index (new_lines, new_lines->len - 1);
+                      new_line = g_strdup_printf ("%s,", previous_line);
+                      g_ptr_array_remove_index (new_lines, new_lines->len - 1);
+                      g_ptr_array_add (new_lines, new_line);
                       right_curly_brace_line = line;
                       line = g_strdup_printf ("%s\"config-opts\": []", primary_module_indent);
                     }


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