[Freeassociation-devel] Fix for crash on Windows when no zoneinfo directory

Mahesh Kumar Maheshkumar.Bg at Sun.COM
Tue Jan 5 16:53:54 PST 2010


Hi,

Here is diff of the fix for crash if there is not zoneinfo directory or 
file on Windows,
Please review this and if appropriate add it to the library

Index: icaltimezone.c
===================================================================
--- icaltimezone.c    (revision 988)
+++ icaltimezone.c    (working copy)
@@ -1670,17 +1671,30 @@
     int latitude_degrees = 0, latitude_minutes = 0, latitude_seconds = 0;
     int longitude_degrees = 0, longitude_minutes = 0, longitude_seconds 
= 0;
     icaltimezone zone;
+    char *basedir = NULL;
 
     icalerror_assert (builtin_timezones == NULL,
               "Parsing zones.tab file multiple times");
 
     builtin_timezones = icalarray_new (sizeof (icaltimezone), 32);
 
-#ifndef USE_BUILTIN_TZDATA
-    filename_len = strlen ((char *) icaltzutil_get_zone_directory()) + 
strlen (ZONES_TAB_SYSTEM_FILENAME)
+#ifndef USE_BUILTIN_TZDATA
+    basedir = (char*)icaltzutil_get_zone_directory();
+    if (!basedir) {
+        icalerror_set_errno (ICAL_FILE_ERROR);
+        return;
+    }
+
+    filename_len = strlen ((char *) basedir) + strlen 
(ZONES_TAB_SYSTEM_FILENAME)
     + 2;
 #else    
-    filename_len = strlen (get_zone_directory()) + strlen 
(ZONES_TAB_FILENAME)
+    basedir = (char*)get_zone_directory();
+    if (!basedir) {
+        icalerror_set_errno (ICAL_FILE_ERROR);
+        return;
+    }
+
+    filename_len = strlen (basedir) + strlen (ZONES_TAB_FILENAME)
     + 2;
 #endif    
 
@@ -1690,10 +1704,10 @@
     return;
     }
 #ifndef USE_BUILTIN_TZDATA
-    snprintf (filename, filename_len, "%s/%s", 
icaltzutil_get_zone_directory (),
+    snprintf (filename, filename_len, "%s/%s", basedir,
           ZONES_TAB_SYSTEM_FILENAME);
 #else    
-    snprintf (filename, filename_len, "%s/%s", get_zone_directory(),
+    snprintf (filename, filename_len, "%s/%s", basedir,
           ZONES_TAB_FILENAME);
 #endif 



================================================


Thanks,
Mahesh




More information about the libical-devel mailing list