]> Pileus Git - ~andy/gtk/commitdiff
bgo#514843 - [filechooser] Deal with corrupted .gtk-bookmarks gracefully
authorJohn Ralls <jralls@ceridwen.us>
Mon, 12 Sep 2011 19:25:45 +0000 (14:25 -0500)
committerFederico Mena Quintero <federico@gnome.org>
Mon, 12 Sep 2011 19:30:44 +0000 (14:30 -0500)
We weren't checking for the lines in that file being valid UTF-8 strings.

gtk/gtkfilesystem.c

index f3d8e823a0eaf1a78aa2d7612593416c859a0040..e55f83b36b832e30b1d33d89cc3d0898d46353a8 100644 (file)
@@ -264,6 +264,9 @@ read_bookmarks (GFile *file)
       if (!*lines[i])
        continue;
 
+      if (!g_utf8_validate (lines[i], -1, NULL))
+       continue;
+
       bookmark = g_slice_new0 (GtkFileSystemBookmark);
 
       if ((space = strchr (lines[i], ' ')) != NULL)
@@ -289,23 +292,25 @@ save_bookmarks (GFile  *bookmarks_file,
 {
   GError *error = NULL;
   GString *contents;
+  GSList *l;
 
   contents = g_string_new ("");
 
-  while (bookmarks)
+  for (l = bookmarks; l; l = l->next)
     {
-      GtkFileSystemBookmark *bookmark;
+      GtkFileSystemBookmark *bookmark = l->data;
       gchar *uri;
 
-      bookmark = bookmarks->data;
       uri = g_file_get_uri (bookmark->file);
+      if (!uri)
+       continue;
+
       g_string_append (contents, uri);
 
       if (bookmark->label)
        g_string_append_printf (contents, " %s", bookmark->label);
 
       g_string_append_c (contents, '\n');
-      bookmarks = bookmarks->next;
       g_free (uri);
     }