[evolution-data-server/gnome-3-8] Bug 697705 - e_cal_client_remove_objects_sync() crashes on empty UID



commit ea8be5c32d94afc75c0cf13ed76dd7e8453154f5
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Apr 14 10:31:20 2013 -0400

    Bug 697705 - e_cal_client_remove_objects_sync() crashes on empty UID
    
    (cherry picked from commit ae2f0b7e81be5d633860a7f05b9ee810ae1945c3)

 calendar/libecal/e-cal-client.c                  | 35 +++++++++++++++++++-----
 tests/libecal/client/test-client-remove-object.c | 25 +++++++++++++++++
 2 files changed, 53 insertions(+), 7 deletions(-)
---
diff --git a/calendar/libecal/e-cal-client.c b/calendar/libecal/e-cal-client.c
index 8f8d8e3..0a10e48 100644
--- a/calendar/libecal/e-cal-client.c
+++ b/calendar/libecal/e-cal-client.c
@@ -5283,7 +5283,8 @@ e_cal_client_remove_objects_sync (ECalClient *client,
        GFlagsClass *flags_class;
        GFlagsValue *flags_value;
        GString *flags;
-       gboolean success;
+       guint n_valid_uids = 0;
+       gboolean success = TRUE;
 
        g_return_val_if_fail (E_IS_CAL_CLIENT (client), FALSE);
        g_return_val_if_fail (ids != NULL, FALSE);
@@ -5299,7 +5300,7 @@ e_cal_client_remove_objects_sync (ECalClient *client,
                flags_value = g_flags_get_first_value (flags_class, mod);
        }
 
-       g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
+       g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ss)"));
        while (ids != NULL) {
                ECalComponentId *id = ids->data;
                gchar *utf8_uid;
@@ -5307,9 +5308,23 @@ e_cal_client_remove_objects_sync (ECalClient *client,
 
                ids = g_slist_next (ids);
 
-               if (id->uid == NULL || *id->uid == '\0')
+               if (id->uid == NULL)
                        continue;
 
+               /* Reject empty UIDs with an OBJECT_NOT_FOUND error for
+                * backward-compatibility, even though INVALID_ARG might
+                * be more appropriate. */
+               if (*id->uid == '\0') {
+                       g_set_error_literal (
+                               error, E_CAL_CLIENT_ERROR,
+                               E_CAL_CLIENT_ERROR_OBJECT_NOT_FOUND,
+                               e_cal_client_error_to_string (
+                               E_CAL_CLIENT_ERROR_OBJECT_NOT_FOUND));
+                       n_valid_uids = 0;
+                       success = FALSE;
+                       break;
+               }
+
                utf8_uid = e_util_utf8_make_valid (id->uid);
                if (id->rid != NULL)
                        utf8_rid = e_util_utf8_make_valid (id->rid);
@@ -5320,12 +5335,18 @@ e_cal_client_remove_objects_sync (ECalClient *client,
 
                g_free (utf8_uid);
                g_free (utf8_rid);
+
+               n_valid_uids++;
        }
 
-       success = e_dbus_calendar_call_remove_objects_sync (
-               client->priv->dbus_proxy,
-               g_variant_builder_end (&builder),
-               flags->str, cancellable, error);
+       if (n_valid_uids > 0) {
+               success = e_dbus_calendar_call_remove_objects_sync (
+                       client->priv->dbus_proxy,
+                       g_variant_builder_end (&builder),
+                       flags->str, cancellable, error);
+       } else {
+               g_variant_builder_clear (&builder);
+       }
 
        g_type_class_unref (flags_class);
        g_string_free (flags, TRUE);
diff --git a/tests/libecal/client/test-client-remove-object.c 
b/tests/libecal/client/test-client-remove-object.c
index ef39586..4b4287f 100644
--- a/tests/libecal/client/test-client-remove-object.c
+++ b/tests/libecal/client/test-client-remove-object.c
@@ -86,6 +86,24 @@ test_remove_object_async (ETestServerFixture *fixture,
        g_main_loop_run (fixture->loop);
 }
 
+static void
+test_remove_object_empty_uid (ETestServerFixture *fixture,
+                              gconstpointer user_data)
+{
+       ECalClient *cal_client;
+       GError *error = NULL;
+
+       g_test_bug ("697705");
+
+       cal_client = E_TEST_SERVER_UTILS_SERVICE (fixture, ECalClient);
+
+       e_cal_client_remove_object_sync (
+               cal_client, "", NULL, E_CAL_OBJ_MOD_ALL, NULL, &error);
+       g_assert_error (
+               error, E_CAL_CLIENT_ERROR,
+               E_CAL_CLIENT_ERROR_OBJECT_NOT_FOUND);
+}
+
 gint
 main (gint argc,
       gchar **argv)
@@ -110,6 +128,13 @@ main (gint argc,
                e_test_server_utils_setup,
                test_remove_object_async,
                e_test_server_utils_teardown);
+       g_test_add (
+               "/ECalClient/RemoveObject/EmptyUid",
+               ETestServerFixture,
+               &cal_closure,
+               e_test_server_utils_setup,
+               test_remove_object_empty_uid,
+               e_test_server_utils_teardown);
 
        return e_test_server_utils_run ();
 }


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