[evolution-patches] Exchange : Plugins



Hi,

While reading through the code i came across places that might cause
crashes because of missing NULL checks. Please review.

Thanks
-- Sarfraaz
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/ChangeLog,v
retrieving revision 1.37
diff -u -p -u -p -r1.37 ChangeLog
--- ChangeLog	1 Aug 2005 06:46:30 -0000	1.37
+++ ChangeLog	2 Aug 2005 09:01:02 -0000
@@ -1,4 +1,12 @@
+2005-08-02  Sarfraaz Ahmed <asarfraaz novell com>
+
+	* exchange-calendar.c : Check for NULL target
+	* exchange-contacts.c : Similar
+	* exchange-folder-permission.c : Similar
+	* exchange-folder.c : Similar
+
 2005-08-01  Praveen Kumar  <kpraveen novell com>
+
 	* exchnage-config-listener.c 
 	(exchange_add_autocompletion_folders) : Added new
 	(add_defaults_for_account) : Added a call to the newly added function
Index: exchange-calendar.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-calendar.c,v
retrieving revision 1.7
diff -u -p -u -p -r1.7 exchange-calendar.c
--- exchange-calendar.c	25 Jul 2005 08:40:00 -0000	1.7
+++ exchange-calendar.c	2 Aug 2005 09:01:02 -0000
@@ -142,7 +142,7 @@ e_exchange_calendar_pcalendar (EPlugin *
 	GtkListStore *model;
 	GPtrArray *callist;
 	ECalConfigTargetSource *t = (ECalConfigTargetSource *) data->target;
-	ESource *source = t->source;
+	ESource *source;
 	EUri *uri;
 	ExchangeAccount *account;
 	gchar *ruri;
@@ -152,6 +152,11 @@ e_exchange_calendar_pcalendar (EPlugin *
 	char *folder_size;
 	int row, i;
 
+	if (!t)
+		return NULL;
+
+	source = t->source;
+
 	if (!hidden)
 		hidden = gtk_label_new ("");
 
@@ -274,10 +279,18 @@ e_exchange_calendar_check (EPlugin *epl,
 {
 	/* FIXME - check pageid */
 	ECalConfigTargetSource *t = (ECalConfigTargetSource *) data->target;
-	ESourceGroup *group = e_source_peek_group (t->source);
-
-	if (!strncmp (e_source_group_peek_base_uri (group), "exchange", 8)) {
-		if (!strlen (e_source_peek_relative_uri (t->source))) {
+	ESourceGroup *group;
+	const char *base_uri;
+	const char *rel_uri;
+
+	if (!t)
+		return TRUE;
+
+	rel_uri = e_source_peek_relative_uri (t->source);
+	group = e_source_peek_group (t->source);
+	base_uri = e_source_group_peek_base_uri (group);
+	if (base_uri && !strncmp (base_uri, "exchange", 8)) {
+		if (rel_uri && !strlen (e_source_peek_relative_uri (t->source))) {
 			return FALSE;
 		}
 	}
@@ -289,13 +302,16 @@ void 
 e_exchange_calendar_commit (EPlugin *epl, EConfigTarget *target)
 {
 	ECalConfigTargetSource *t = (ECalConfigTargetSource *) target;
-	ESource *source = t->source;
+	ESource *source;
 	gchar *uri_text, *gruri, *gname, *ruri, *ftype, *path, *path_prefix, *oldpath=NULL;
 	int prefix_len;
-
 	ExchangeAccount *account;
 	ExchangeAccountFolderResult result;
 		
+	if (!t)
+		return;
+
+	source = t->source;
 	uri_text = e_source_get_uri (source);
 	if (strncmp (uri_text, "exchange", 8)) {
 		g_free (uri_text);
Index: exchange-contacts.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-contacts.c,v
retrieving revision 1.6
diff -u -p -u -p -r1.6 exchange-contacts.c
--- exchange-contacts.c	25 Jul 2005 08:40:00 -0000	1.6
+++ exchange-contacts.c	2 Aug 2005 09:01:02 -0000
@@ -133,6 +133,10 @@ e_exchange_contacts_pcontacts (EPlugin *
 	char *folder_size, *abook_name;
 
 	EABConfigTargetSource *t = (EABConfigTargetSource *) data->target;
+
+	if (!t)
+		return NULL;
+
 	ESource *source = t->source;
 
 	if (data->old) {
@@ -258,10 +262,18 @@ e_exchange_contacts_check (EPlugin *epl,
 {
 	/* FIXME - check pageid */
 	EABConfigTargetSource *t = (EABConfigTargetSource *) data->target;
-	ESourceGroup *group = e_source_peek_group (t->source);
-
-	if (!strncmp (e_source_group_peek_base_uri (group), "exchange", 8)) {
-		if (!strlen (e_source_peek_relative_uri (t->source))) {
+	ESourceGroup *group;
+	const char *base_uri;
+	const char *rel_uri;
+
+	if (!t)
+		return FALSE;
+
+	rel_uri = e_source_peek_relative_uri (t->source);
+	group = e_source_peek_group (t->source);
+	base_uri = e_source_group_peek_base_uri (group);
+	if (base_uri && !strncmp (base_uri, "exchange", 8)) {
+		if (rel_uri && !strlen (rel_uri)) {
 			return FALSE;
 		}
 	}
@@ -276,10 +288,13 @@ e_exchange_contacts_commit (EPlugin *epl
 	ESource *source = t->source;
 	gchar *uri_text, *gname, *gruri, *ruri, *path, *path_prefix, *oldpath=NULL;
 	int prefix_len;
-
 	ExchangeAccount *account;
 	ExchangeAccountFolderResult result;
 		
+	if (!t)
+		return;
+
+	source = t->source;
 	uri_text = e_source_get_uri (source);
 	if (strncmp (uri_text, "exchange", 8)) {
 		g_free (uri_text);
Index: exchange-folder-permission.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-folder-permission.c,v
retrieving revision 1.5
diff -u -p -u -p -r1.5 exchange-folder-permission.c
--- exchange-folder-permission.c	25 Jul 2005 07:37:03 -0000	1.5
+++ exchange-folder-permission.c	2 Aug 2005 09:01:03 -0000
@@ -74,6 +74,11 @@ org_gnome_exchange_calendar_permissions 
 	ESource *source = NULL;
 	gchar *uri = NULL;
 
+	account = exchange_operations_get_exchange_account ();
+
+	if (!target || !account)
+		return;
+
 	source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
 	uri = (gchar *) e_source_get_uri (source);
 
@@ -81,11 +86,6 @@ org_gnome_exchange_calendar_permissions 
 		return ;
 	}
 
-	account = exchange_operations_get_exchange_account ();
-
-	if (!account)
-		return;
-
 	folder = exchange_account_get_folder (account, uri);
 
 	if (!folder)
@@ -118,6 +118,11 @@ org_gnome_exchange_addressbook_permissio
 	ESource *source = NULL;
 	gchar *uri = NULL;
 
+	account = exchange_operations_get_exchange_account ();
+
+	if (!target || !account)
+		return;
+
 	source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
 	uri = (gchar *) e_source_get_uri (source);
 
@@ -125,12 +130,6 @@ org_gnome_exchange_addressbook_permissio
 		return ;
 	}
 
-	account = exchange_operations_get_exchange_account ();
-
-	if (!account)
-		return;
-
-
 	folder = exchange_account_get_folder (account, uri);
 
 	if (!folder) {
@@ -152,7 +151,7 @@ org_gnome_exchange_addressbook_permissio
 }
 
 void
-org_gnome_exchange_folder_permissions (EPlugin *ep, EMPopupTargetFolder *t)
+org_gnome_exchange_folder_permissions (EPlugin *ep, EMPopupTargetFolder *target)
 {
 	GSList *menus = NULL;
 	int i = 0;
@@ -160,21 +159,21 @@ org_gnome_exchange_folder_permissions (E
 	ExchangeAccount *account = NULL;
 	EFolder *folder = NULL;
 
-	if (! g_strrstr (t->uri, "exchange://"))
-		return ;
-
 	account = exchange_operations_get_exchange_account ();
 
-	if (!account)
+	if (!target || !account)
 		return;
 
-	folder = exchange_account_get_folder (account, t->uri);
+	if (! g_strrstr (target->uri, "exchange://"))
+		return ;
+
+	folder = exchange_account_get_folder (account, target->uri);
 
 
 	if (!folder)
 		return;
 
-	selected_exchange_folder_uri = t->uri;
+	selected_exchange_folder_uri = target->uri;
 	/* for translation*/
 	if (!first) {
 		popup_items[0].label =  _(popup_items[0].label);
@@ -184,7 +183,7 @@ org_gnome_exchange_folder_permissions (E
 	for (i = 0; i < sizeof (popup_items) / sizeof (popup_items[0]); i++)
 		menus = g_slist_prepend (menus, &popup_items[i]);
 
-	e_popup_add_items (t->target.popup, menus, NULL, popup_free, NULL);
+	e_popup_add_items (target->target.popup, menus, NULL, popup_free, NULL);
 
 }
 
@@ -211,12 +210,9 @@ org_gnome_exchange_menu_folder_permissio
 	ExchangeAccount *account = NULL;
 	EFolder *folder = NULL;
 
-	if (target == NULL)
-		return;
-
 	account = exchange_operations_get_exchange_account ();
 
-	if (!account)
+	if (!target || !account)
 		return;
 
 	folder = exchange_account_get_folder (account, target->uri);
Index: exchange-folder.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-folder.c,v
retrieving revision 1.6
diff -u -p -u -p -r1.6 exchange-folder.c
--- exchange-folder.c	28 Jul 2005 18:05:12 -0000	1.6
+++ exchange-folder.c	2 Aug 2005 09:01:03 -0000
@@ -80,7 +80,7 @@ org_gnome_exchange_check_inbox_subscribe
 
 	account = exchange_operations_get_exchange_account ();
 
-	if (!account)
+	if (!account || !target)
 		return;
 
 	path = g_strdup_printf (target->uri + strlen ("exchange://") + strlen (account->account_filename));
@@ -130,7 +130,7 @@ org_gnome_exchange_check_address_book_su
 
 	account = exchange_operations_get_exchange_account ();
 
-	if (!account)
+	if (!account || !target)
 		return;
 
 	source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
@@ -169,7 +169,7 @@ org_gnome_exchange_check_subscribed (EPl
 
 	account = exchange_operations_get_exchange_account ();
 
-	if (!account)
+	if (!account || !target)
 		return;
 
 	source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
@@ -211,7 +211,7 @@ unsubscribe_dialog_ab_response (GtkDialo
 
 		account = exchange_operations_get_exchange_account ();
 
-		if (!account)
+		if (!account || !target)
 			return;
 
 		source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
@@ -251,7 +251,7 @@ unsubscribe_dialog_response (GtkDialog *
 
 		account = exchange_operations_get_exchange_account ();
 
-		if (!account)
+		if (!account || !target)
 			return;
 
 		source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
@@ -304,7 +304,7 @@ org_gnome_exchange_folder_ab_unsubscribe
 
 	account = exchange_operations_get_exchange_account ();
 
-	if (!account)
+	if (!account || !target)
 		return;
 
 	source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
@@ -347,7 +347,7 @@ org_gnome_exchange_folder_unsubscribe (E
 
 	account = exchange_operations_get_exchange_account ();
 
-	if (!account)
+	if (!account || !target)
 		return;
 
 	source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
@@ -393,7 +393,7 @@ org_gnome_exchange_folder_subscription (
 
 	account = exchange_operations_get_exchange_account ();
 
-	if (!account)
+	if (!account || !target)
 		return;
 
 	create_folder_subscription_dialog (account->account_name, &user_email_address, &folder_name);


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