libical/libical-0.46-icaltimezone.patch
Robert Scheck 5caa9c402e - Upgrade to 0.46 (#525933, #628893)
- Fixed race in populating builtin timezone components (#637150)
- Fixed wrong ICAL_ERRORS_ARE_FATAL preprocessor check (#575715)
2010-12-19 22:06:07 +01:00

99 lines
2.5 KiB
Diff

Patch by David Woodhouse <dwmw2@infradead.org> for libical >= 0.46, which fixes a race in populating
builtin timezone components. When multiple threads call icaltimezone_get_component() for the same
zone, it can be populated by icaltimezone_load_builtin_timezone() multiple times simultaneously, and
bad things happen. More details can be found at: https://bugzilla.redhat.com/show_bug.cgi?id=637150
This patch is already part of upstream and thus should be obsolete once libical 0.47 gets released.
--- libical-0.46/src/libical/icaltimezone.c 2010-08-30 22:05:06.000000000 +0200
+++ libical-0.46/src/libical/icaltimezone.c.icaltimezone 2010-12-19 20:37:11.000000000 +0100
@@ -45,6 +45,11 @@
#include <sys/stat.h>
+#ifdef HAVE_PTHREAD
+#include <pthread.h>
+static pthread_mutex_t builtin_mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
#ifdef WIN32
#include <mbstring.h>
#include <windows.h>
@@ -453,8 +458,7 @@
int changes_end_year;
- if (!zone->component)
- icaltimezone_load_builtin_timezone (zone);
+ icaltimezone_load_builtin_timezone (zone);
if (icaltimezone_minimum_expansion_year == -1) {
struct icaltimetype today = icaltime_today();
@@ -1140,8 +1144,7 @@
if (!zone)
return NULL;
- if (!zone->tzid)
- icaltimezone_load_builtin_timezone (zone);
+ icaltimezone_load_builtin_timezone (zone);
return zone->tzid;
}
@@ -1167,8 +1170,7 @@
if (!zone)
return NULL;
- if (!zone->component)
- icaltimezone_load_builtin_timezone (zone);
+ icaltimezone_load_builtin_timezone (zone);
return zone->tznames;
}
@@ -1210,8 +1212,7 @@
if (!zone)
return NULL;
- if (!zone->component)
- icaltimezone_load_builtin_timezone (zone);
+ icaltimezone_load_builtin_timezone (zone);
return zone->component;
}
@@ -1449,8 +1450,7 @@
for (i=0; i<count; i++) {
int z_offset;
zone = icalarray_element_at (builtin_timezones, i);
- if (!zone->component)
- icaltimezone_load_builtin_timezone (zone);
+ icaltimezone_load_builtin_timezone (zone);
z_offset = get_offset(zone);
@@ -1745,6 +1745,12 @@
if (!zone->location || !zone->location[0])
return;
+#ifdef HAVE_PTHREAD
+ pthread_mutex_lock(&builtin_mutex);
+ if (zone->component)
+ goto out;
+#endif
+
#ifdef USE_BUILTIN_TZDATA
{
char *filename;
@@ -1801,8 +1807,11 @@
icalcomponent_remove_component(comp,subcomp);
icalcomponent_free(comp);
}
-#endif
-
+#endif
+#ifdef HAVE_PTHREAD
+ out:
+ pthread_mutex_unlock(&builtin_mutex);
+#endif
}