Don't leave dangling pointers in the GcalEvent cache

The cache has an unowned pointer to the GcalEvent's UID. We need to
update the cache with the GcalEvent's new UID to avoid use-after-free.

Fixes #434
This commit is contained in:
Michael Catanzaro
2019-08-25 17:39:01 +03:00
committed by Georges Basile Stavracas Neto
parent 15bf7892fa
commit 748b7207e7
+15 -2
View File
@@ -256,13 +256,20 @@ gcal_event_update_uid_internal (GcalEvent *self)
{
ECalComponentId *id;
const gchar *source_id;
gboolean should_update_cache;
/* Setup event uid */
source_id = self->calendar ? gcal_calendar_get_id (self->calendar) : "";
id = e_cal_component_get_id (self->component);
/* Clear the previous uid */
g_clear_pointer (&self->uid, g_free);
should_update_cache = self->uid != NULL;
if (should_update_cache)
{
g_debug ("Removing '%s' (%p) from cache", self->uid, self);
g_hash_table_remove (event_cache, self->uid);
g_clear_pointer (&self->uid, g_free);
}
if (e_cal_component_id_get_rid (id) != NULL)
{
@@ -278,6 +285,12 @@ gcal_event_update_uid_internal (GcalEvent *self)
e_cal_component_id_get_uid (id));
}
if (should_update_cache)
{
g_debug ("Adding %s to the cache", self->uid);
g_hash_table_insert (event_cache, self->uid, self);
}
e_cal_component_id_free (id);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_UID]);
}