[gnome-calendar/mcatanzaro/#419] Fix crashes when e_cal_util_get_system_timezone() returns NULL



commit 7101c5ca5134f78d77348824c3bfbdcf0a9659c0
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Wed Jul 3 11:28:02 2019 -0500

    Fix crashes when e_cal_util_get_system_timezone() returns NULL
    
    The return value is nullable so gnome-calendar had better check it.
    
    I assume falling back to UTC is a sane behavior in this case.
    
    Fixes #419

 src/core/gcal-event.c           |  9 ++++++---
 src/core/gcal-manager.c         | 26 ++++++++++++++++++++++----
 src/search/gcal-search-engine.c |  5 ++++-
 src/utils/gcal-utils.c          | 14 +++++++++-----
 4 files changed, 41 insertions(+), 13 deletions(-)
---
diff --git a/src/core/gcal-event.c b/src/core/gcal-event.c
index ef16bf04..a59bfd99 100644
--- a/src/core/gcal-event.c
+++ b/src/core/gcal-event.c
@@ -224,7 +224,7 @@ build_component_from_datetime (GcalEvent *self,
                                GDateTime *dt)
 {
   ICalTime *itt;
-  gchar *tzid;
+  gchar *tzid = NULL;
 
   if (!dt)
     return NULL;
@@ -241,8 +241,11 @@ build_component_from_datetime (GcalEvent *self,
       ICalTimezone *zone;
 
       zone = e_cal_util_get_system_timezone ();
-      i_cal_time_set_timezone (itt, zone);
-      tzid = zone ? g_strdup (i_cal_timezone_get_tzid (zone)) : NULL;
+      if (zone != NULL)
+        {
+          i_cal_time_set_timezone (itt, zone);
+          tzid = g_strdup (i_cal_timezone_get_tzid (zone));
+         }
     }
 
   /* Call it after setting the timezone, because the DATE values do not let set the timezone */
diff --git a/src/core/gcal-manager.c b/src/core/gcal-manager.c
index 51619906..a4d8bc9e 100644
--- a/src/core/gcal-manager.c
+++ b/src/core/gcal-manager.c
@@ -876,6 +876,8 @@ void
 gcal_manager_setup_shell_search (GcalManager             *self,
                                  ECalDataModelSubscriber *subscriber)
 {
+  ICalTimezone *tz;
+
   g_return_if_fail (GCAL_IS_MANAGER (self));
 
   if (self->shell_search_data_model)
@@ -888,7 +890,9 @@ gcal_manager_setup_shell_search (GcalManager             *self,
                             self);
 
   e_cal_data_model_set_expand_recurrences (self->shell_search_data_model, TRUE);
-  e_cal_data_model_set_timezone (self->shell_search_data_model, e_cal_util_get_system_timezone ());
+  tz = e_cal_util_get_system_timezone ();
+  if (tz != NULL)
+    e_cal_data_model_set_timezone (self->shell_search_data_model, tz);
 
   self->search_view_data = g_new0 (ViewStateData, 1);
   self->search_view_data->subscriber = subscriber;
@@ -1419,6 +1423,7 @@ gcal_manager_get_events (GcalManager *self,
                          ICalTime    *end_date)
 {
   time_t range_start, range_end;
+  ICalTimezone *tz;
   GatherEventData data = {
     .manager = self,
     .events = NULL,
@@ -1428,8 +1433,18 @@ gcal_manager_get_events (GcalManager *self,
 
   g_return_val_if_fail (GCAL_IS_MANAGER (self), NULL);
 
-  range_start = i_cal_time_as_timet_with_zone (start_date, e_cal_util_get_system_timezone ());
-  range_end = i_cal_time_as_timet_with_zone (end_date, e_cal_util_get_system_timezone ());
+  tz = e_cal_util_get_system_timezone ();
+
+  if (tz)
+    {
+      range_start = i_cal_time_as_timet_with_zone (start_date, tz);
+      range_end = i_cal_time_as_timet_with_zone (end_date, tz);
+    }
+  else
+    {
+      range_start = i_cal_time_as_timet (start_date);
+      range_end = i_cal_time_as_timet (end_date);
+    }
 
   e_cal_data_model_foreach_component (self->e_data_model,
                                       range_start,
@@ -1519,6 +1534,7 @@ gcal_manager_startup (GcalManager *self)
   GList *sources, *l;
   GError *error = NULL;
   ESourceCredentialsProvider *credentials_provider;
+  ICalTimezone *tz;
 
   GCAL_ENTRY;
 
@@ -1619,7 +1635,9 @@ gcal_manager_startup (GcalManager *self)
   self->e_data_model = e_cal_data_model_new (gcal_thread_submit_job);
 
   e_cal_data_model_set_expand_recurrences (self->e_data_model, TRUE);
-  e_cal_data_model_set_timezone (self->e_data_model, e_cal_util_get_system_timezone ());
+  tz = e_cal_util_get_system_timezone ();
+  if (tz != NULL)
+    e_cal_data_model_set_timezone (self->e_data_model, tz);
 
   sources = e_source_registry_list_enabled (self->source_registry, E_SOURCE_EXTENSION_CALENDAR);
 
diff --git a/src/search/gcal-search-engine.c b/src/search/gcal-search-engine.c
index eadbf80d..afc241c5 100644
--- a/src/search/gcal-search-engine.c
+++ b/src/search/gcal-search-engine.c
@@ -177,13 +177,16 @@ gcal_search_engine_constructed (GObject *object)
 {
   GcalSearchEngine *self = (GcalSearchEngine *)object;
   GcalManager *manager;
+  ICalTimezone *tz;
 
   G_OBJECT_CLASS (gcal_search_engine_parent_class)->constructed (object);
 
   /* Setup the data model */
   self->data_model = e_cal_data_model_new (gcal_thread_submit_job);
   e_cal_data_model_set_expand_recurrences (self->data_model, TRUE);
-  e_cal_data_model_set_timezone (self->data_model, e_cal_util_get_system_timezone ());
+  tz = e_cal_util_get_system_timezone ();
+  if (tz != NULL)
+    e_cal_data_model_set_timezone (self->data_model, tz);
 
 
   manager = gcal_context_get_manager (self->context);
diff --git a/src/utils/gcal-utils.c b/src/utils/gcal-utils.c
index 495efc0a..f6de0e55 100644
--- a/src/utils/gcal-utils.c
+++ b/src/utils/gcal-utils.c
@@ -371,7 +371,7 @@ build_component_from_details (const gchar *summary,
   ECalComponent *event;
   ECalComponentDateTime *dt;
   ECalComponentText *summ;
-  ICalTimezone *zone;
+  ICalTimezone *zone = NULL;
   ICalTime *itt;
   gboolean all_day;
 
@@ -388,13 +388,13 @@ build_component_from_details (const gchar *summary,
    * When the event is all day, we consider UTC timezone by default. Otherwise,
    * we always use the system timezone to create new events
    */
-  if (all_day)
+  if (!all_day)
     {
-      zone = i_cal_timezone_get_utc_timezone ();
+      zone = e_cal_util_get_system_timezone ();
     }
-  else
+  if (zone == NULL)
     {
-      zone = e_cal_util_get_system_timezone ();
+      zone = i_cal_timezone_get_utc_timezone ();
     }
 
   /* Start date */
@@ -482,10 +482,14 @@ icaltime_compare_with_current (const ICalTime *date1,
   zone1 = i_cal_time_get_timezone (date1);
   if (!zone1)
     zone1 = e_cal_util_get_system_timezone ();
+  if (!zone1)
+    zone1 = i_cal_timezone_get_utc_timezone ();
 
   zone2 = i_cal_time_get_timezone (date2);
   if (!zone2)
     zone2 = e_cal_util_get_system_timezone ();
+  if (!zone2)
+    zone2 = i_cal_timezone_get_utc_timezone ();
 
   start1 = i_cal_time_as_timet_with_zone (date1, zone1);
   start2 = i_cal_time_as_timet_with_zone (date2, zone2);


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