[evolution-patches] Addressbook - Patch for #74366



Hi,

bbdb plugin crashes on NULL query.
Query is becoming NULL when name has some invalid characters.

Please review.
-Sushma.
Index: plugins/bbdb/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/plugins/bbdb/ChangeLog,v
retrieving revision 1.13
diff -u -p -r1.13 ChangeLog
--- plugins/bbdb/ChangeLog	6 Apr 2005 05:42:30 -0000	1.13
+++ plugins/bbdb/ChangeLog	7 Apr 2005 13:09:53 -0000
@@ -1,3 +1,11 @@
+2005-04-07  Sushma Rai  <rsushma novell com>
+
+	* bbdb.c (bbdb_handle_reply): Check for camel_internet_address_get()
+	return value. 
+	(bbdb_do_it): Check for query being NULL. Fixes #74366.
+	Free list of contacts before returning, on finding multiple contacts 
+	with the same name.
+
 2005-04-05  Not Zed  <NotZed Ximian com>
 
 	* bbdb.c (bbdb_handle_reply): noop if we can't open the book/we're
Index: plugins/bbdb/bbdb.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/bbdb/bbdb.c,v
retrieving revision 1.7
diff -u -p -r1.7 bbdb.c
--- plugins/bbdb/bbdb.c	6 Apr 2005 05:42:30 -0000	1.7
+++ plugins/bbdb/bbdb.c	7 Apr 2005 13:10:13 -0000
@@ -106,8 +106,6 @@ void
 bbdb_handle_reply (EPlugin *ep, EMEventTargetMessage *target)
 {
 	const CamelInternetAddress *cia;
-	const char *name;
-	const char *email;
 	EBook      *book = NULL;
 	int         i;
 
@@ -117,8 +115,10 @@ bbdb_handle_reply (EPlugin *ep, EMEventT
 		return;
 
 	cia = camel_mime_message_get_from (target->message);
-	for (i = 0; i < camel_address_length CAMEL_ADDRESS (cia); i ++) {
-		camel_internet_address_get (cia, i, &name, &email);
+	for (i = 0; i < camel_address_length (CAMEL_ADDRESS (cia)); i ++) {
+		const char *name, *email;
+		if (!(camel_internet_address_get (cia, i, &name, &email)))
+			continue;
 		bbdb_do_it (book, name, email);
 	}
 
@@ -129,14 +129,18 @@ bbdb_handle_reply (EPlugin *ep, EMEventT
 	}
 
 	cia = camel_mime_message_get_recipients (target->message, CAMEL_RECIPIENT_TYPE_TO);
-	for (i = 0; i < camel_address_length CAMEL_ADDRESS (cia); i ++) {
-		camel_internet_address_get (cia, i, &name, &email);
+	for (i = 0; i < camel_address_length (CAMEL_ADDRESS (cia)); i ++) {
+		const char *name, *email;
+		if (!(camel_internet_address_get (cia, i, &name, &email)))
+			continue;
 		bbdb_do_it (book, name, email);
 	}
 
 	cia = camel_mime_message_get_recipients (target->message, CAMEL_RECIPIENT_TYPE_CC);
-	for (i = 0; i < camel_address_length CAMEL_ADDRESS (cia); i ++) {
-		camel_internet_address_get (cia, i, &name, &email);
+	for (i = 0; i < camel_address_length (CAMEL_ADDRESS (cia)); i ++) {
+		const char *name, *email;
+		if (!(camel_internet_address_get (cia, i, &name, &email)))
+			continue;
 		bbdb_do_it (book, name, email);
 	}
 
@@ -171,9 +175,9 @@ bbdb_do_it (EBook *book, const char *nam
 	g_free (query_string);
 
 	status = e_book_get_contacts (book, query, &contacts, NULL);
-	e_book_query_unref (query);
+	if (query)
+		e_book_query_unref (query);
 	if (contacts != NULL) {
-		GList *l;
 		for (l = contacts; l != NULL; l = l->next)
 			g_object_unref ((GObject *)l->data);
 		g_list_free (contacts);
@@ -187,13 +191,17 @@ bbdb_do_it (EBook *book, const char *nam
 	g_free (query_string);
 
 	status = e_book_get_contacts (book, query, &contacts, NULL);
-	e_book_query_unref (query);
+	if (query)
+		e_book_query_unref (query);
 	if (contacts != NULL) {
 
 		/* FIXME: If there's more than one contact with this
 		   name, just give up; we're not smart enough for
 		   this. */
 		if (contacts->next != NULL) {
+			for (l = contacts; l != NULL; l = l->next)
+				g_object_unref ((GObject *)l->data);
+			g_list_free (contacts);
 			return;
 		}
 		


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