[seahorse/f20] Backport a fix for a search provider crash

Kalev Lember kalev at fedoraproject.org
Wed Aug 27 10:54:47 UTC 2014


commit 84bd904fd38a5c18641c7997acf43f642b4124fb
Author: Kalev Lember <kalevlember at gmail.com>
Date:   Wed Aug 27 09:48:35 2014 +0200

    Backport a fix for a search provider crash

 ...ider-Don-t-assume-handles-are-still-valid.patch |  136 ++++++++++++++++++++
 seahorse.spec                                      |    9 +-
 2 files changed, 144 insertions(+), 1 deletions(-)
---
diff --git a/0001-search-provider-Don-t-assume-handles-are-still-valid.patch b/0001-search-provider-Don-t-assume-handles-are-still-valid.patch
new file mode 100644
index 0000000..1b5b4dc
--- /dev/null
+++ b/0001-search-provider-Don-t-assume-handles-are-still-valid.patch
@@ -0,0 +1,136 @@
+From 0917935ab92d58e925106badaf904487296208b6 Mon Sep 17 00:00:00 2001
+From: Stef Walter <stefw at gnome.org>
+Date: Wed, 30 Jul 2014 15:51:41 +0200
+Subject: [PATCH] search-provider: Don't assume handles are still valid
+
+We were crashing when we got back search provider handles from
+the shell for objects that no longer existed.
+
+We can't just call gcr_collection_contains() as it assumes that
+it's receiving a valid GObject.
+
+So hold a table of all the handles we've returned and update
+it via weak references.
+
+https://bugzilla.gnome.org/show_bug.cgi?id=733957
+---
+ libseahorse/seahorse-search-provider.c | 49 +++++++++++++++++++++++++++-------
+ 1 file changed, 40 insertions(+), 9 deletions(-)
+
+diff --git a/libseahorse/seahorse-search-provider.c b/libseahorse/seahorse-search-provider.c
+index 95cbe18..c5408fe 100644
+--- a/libseahorse/seahorse-search-provider.c
++++ b/libseahorse/seahorse-search-provider.c
+@@ -42,6 +42,7 @@ struct _SeahorseSearchProvider {
+ 
+ 	SeahorsePredicate base_predicate;
+ 	GcrCollection *collection;
++	GHashTable *handles;
+ };
+ 
+ struct _SeahorseSearchProviderClass {
+@@ -111,6 +112,16 @@ init_predicate (SeahorsePredicate  *predicate,
+ 	predicate->custom_target = terms;
+ }
+ 
++static void
++on_object_gone (gpointer data,
++		GObject *where_the_object_was)
++{
++	GHashTable *handles = data;
++	gchar *str = g_strdup_printf ("%p", (gpointer)where_the_object_was);
++	g_hash_table_remove (handles, str);
++	g_free (str);
++}
++
+ static gboolean
+ handle_get_initial_result_set (SeahorseShellSearchProvider2 *skeleton,
+                                GDBusMethodInvocation        *invocation,
+@@ -131,6 +142,10 @@ handle_get_initial_result_set (SeahorseShellSearchProvider2 *skeleton,
+ 		if (seahorse_predicate_match (&predicate, l->data)) {
+ 			char *str = g_strdup_printf("%p", l->data);
+ 
++			if (!g_hash_table_contains (self->handles, str)) {
++				g_hash_table_insert (self->handles, g_strdup (str), l->data);
++				g_object_weak_ref (l->data, on_object_gone, self->handles);
++			}
+ 			g_ptr_array_add (array, str);
+ 		}
+ 	}
+@@ -166,9 +181,8 @@ handle_get_subsearch_result_set (SeahorseShellSearchProvider2 *skeleton,
+ 	for (i = 0; previous_results[i]; i++) {
+ 		GObject *object;
+ 
+-		sscanf (previous_results[i], "%p", &object);
+-
+-		if (!gcr_collection_contains (self->collection, object)) {
++		object = g_hash_table_lookup (self->handles, previous_results[i]);
++		if (!object || !gcr_collection_contains (self->collection, object)) {
+ 			/* Bogus value */
+ 			continue;
+ 		}
+@@ -206,9 +220,8 @@ handle_get_result_metas (SeahorseShellSearchProvider2 *skeleton,
+ 	for (i = 0; results[i]; i++) {
+ 		GObject *object;
+ 
+-		sscanf (results[i], "%p", &object);
+-
+-		if (!gcr_collection_contains (self->collection, object)) {
++		object = g_hash_table_lookup (self->handles, results[i]);
++		if (!object || !gcr_collection_contains (self->collection, object)) {
+ 			/* Bogus value */
+ 			continue;
+ 		}
+@@ -265,9 +278,8 @@ handle_activate_result (SeahorseShellSearchProvider2 *skeleton,
+ 	SeahorseWidget *key_manager;
+ 	GtkWindow *window;
+ 
+-	sscanf (identifier, "%p", &object);
+-
+-	if (!gcr_collection_contains (self->collection, object) ||
++	object = g_hash_table_lookup (self->handles, identifier);
++	if (!object || !gcr_collection_contains (self->collection, object) ||
+ 	    !SEAHORSE_IS_VIEWABLE (object)) {
+ 		/* Bogus value */
+ 		return TRUE;
+@@ -392,6 +404,8 @@ seahorse_search_provider_init (SeahorseSearchProvider *self)
+ 	filtered = seahorse_collection_new_for_predicate (base,
+ 	                                                  &self->base_predicate, NULL);
+ 	self->collection = GCR_COLLECTION (filtered);
++
++	self->handles = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ }
+ 
+ gboolean
+@@ -433,11 +447,28 @@ seahorse_search_provider_dispose (GObject *object)
+ }
+ 
+ static void
++seahorse_search_provider_finalize (GObject *object)
++{
++	SeahorseSearchProvider *self = SEAHORSE_SEARCH_PROVIDER (object);
++	GHashTableIter iter;
++	gpointer value;
++
++	g_hash_table_iter_init (&iter, self->handles);
++	while (g_hash_table_iter_next (&iter, NULL, &value))
++		g_object_weak_unref (value, on_object_gone, self->handles);
++	g_hash_table_destroy (self->handles);
++
++	G_OBJECT_CLASS (seahorse_search_provider_parent_class)->finalize (object);
++}
++
++
++static void
+ seahorse_search_provider_class_init (SeahorseSearchProviderClass *klass)
+ {
+ 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ 
+ 	object_class->dispose = seahorse_search_provider_dispose;
++	object_class->finalize = seahorse_search_provider_finalize;
+ }
+ 
+ SeahorseSearchProvider *
+-- 
+2.1.0
+
diff --git a/seahorse.spec b/seahorse.spec
index 8e54a74..e643c7c 100644
--- a/seahorse.spec
+++ b/seahorse.spec
@@ -1,6 +1,6 @@
 Name:		seahorse
 Version:	3.10.2
-Release:	1%{?dist}
+Release:	2%{?dist}
 Summary:	A GNOME application for managing encryption keys
 Group:		User Interface/Desktops
 # seahorse is GPLv2+
@@ -10,6 +10,9 @@ URL:            http://projects.gnome.org/seahorse/
 #VCS: git:git://git.gnome.org/seahorse
 Source:         http://download.gnome.org/sources/seahorse/3.10/%{name}-%{version}.tar.xz
 
+# Backported upstream patch for a search provider crash
+Patch0:         0001-search-provider-Don-t-assume-handles-are-still-valid.patch
+
 BuildRequires:  glib2-devel
 BuildRequires:  gtk3-devel
 BuildRequires:  gcr-devel
@@ -56,6 +59,7 @@ operations.  It is a keyring manager.
 
 %prep
 %setup -q
+%patch0 -p1
 
 
 %build
@@ -133,6 +137,9 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || :
 %{_datadir}/gnome-shell/search-providers/seahorse-search-provider.ini
 
 %changelog
+* Wed Aug 27 2014 Kalev Lember <kalevlember at gmail.com> - 3.10.2-2
+- Backport a fix for a search provider crash
+
 * Mon Jan 20 2014 Richard Hughes <rhughes at redhat.com> - 3.10.2-1
 - Update to 3.10.2
 


More information about the scm-commits mailing list