[epiphany/gnome-40] Fix crash when importing bookmarks from Firefox



commit 152d03a28a970f74e741d74ebf818e803e841637
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Thu Apr 8 12:43:18 2021 -0500

    Fix crash when importing bookmarks from Firefox
    
    The problem is the strings returned by get_firefox_profiles() are freed
    with g_free(), which is correct, but we are actually returning pointers
    into the middle of the allocated region, rather than pointers to the
    start of the string. Truncating a string using pointer arithmetic is a
    nice trick for unowned strings, but for owned strings it doesn't work.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1946648
    
    
    (cherry picked from commit 7e31b93d937625602e910d7397d00cc6082a37be)

 src/window-commands.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/src/window-commands.c b/src/window-commands.c
index 8353008a9..6f46496e5 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -138,22 +138,24 @@ static gchar *
 get_path (GIOChannel *channel)
 {
   gchar *line;
-  gchar *path;
+  const gchar *path;
+  gchar *result;
   gsize length;
 
   do {
     g_io_channel_read_line (channel, &line, &length, NULL, NULL);
 
     if (g_str_has_prefix (line, "Path")) {
-      path = g_strdup (line);
+      path = line;
 
       /* Extract value (e.g. Path=Value\n -> Value) */
       path = strchr (path, '=');
       path++;
-      path[strcspn (path, "\n")] = 0;
+      ((gchar *)path)[strcspn (path, "\n")] = '\0';
+      result = g_strdup (path);
 
       g_free (line);
-      return path;
+      return result;
     }
 
     g_free (line);


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