]> diplodocus.org Git - nmh/commitdiff
Remove any enclosing quotes from a timezone identifier in an
authorDavid Levine <levinedl@acm.org>
Wed, 18 Nov 2015 23:35:59 +0000 (18:35 -0500)
committerDavid Levine <levinedl@acm.org>
Wed, 18 Nov 2015 23:35:59 +0000 (18:35 -0500)
iCalendar event request.  See comment added to format_datetime()
that says that I don't believe that RFC 5545 allows them to be
quoted.  But Oliver Kiddle found them in the wild.

sbr/datetime.c
test/mhical/test-mhical

index 8b2513621e8ce4ea4cf805e21dab2c3a6465cf2b..34287b2331c54ca50f058b99a042719b3ffe64b0 100644 (file)
@@ -199,7 +199,11 @@ load_timezones (const contentline *clines) {
                 in_daylight = 1;
                 params = &timezone->daylight_params;
             } else if (! strcasecmp ("TZID", node->name)) {
                 in_daylight = 1;
                 params = &timezone->daylight_params;
             } else if (! strcasecmp ("TZID", node->name)) {
-                timezone->tzid = strdup (node->value);
+                /* See comment below in format_datetime() about removing any enclosing quotes from a
+                   timezone identifier. */
+                char *buf = mh_xmalloc(strlen(node->value) + 1);
+                unquote_string(node->value, buf);
+                timezone->tzid = buf;
             }
         } else {
             if (! strcasecmp ("BEGIN", node->name)  &&
             }
         } else {
             if (! strcasecmp ("BEGIN", node->name)  &&
@@ -329,7 +333,15 @@ format_datetime (tzdesc_t timezones, const contentline *node) {
     /* Extract the timezone, if specified (RFC 5545 Sec. 3.3.5 Form #3). */
     for (p = node->params; p && p->param_name; p = p->next) {
         if (! strcasecmp (p->param_name, "TZID")  &&  p->values) {
     /* Extract the timezone, if specified (RFC 5545 Sec. 3.3.5 Form #3). */
     for (p = node->params; p && p->param_name; p = p->next) {
         if (! strcasecmp (p->param_name, "TZID")  &&  p->values) {
-            dt_timezone = p->values->value;
+            /* Remove any enclosing quotes from the timezone identifier.  I don't believe that it's
+               legal for it to be quoted, according to RFC 5545 ยง 3.2.19:
+                   tzidparam  = "TZID" "=" [tzidprefix] paramtext
+                   tzidprefix = "/"
+               where paramtext includes SAFE-CHAR, which specifically excludes DQUOTE.  But we'll
+               be generous and strip quotes. */
+            char *buf = mh_xmalloc(strlen(p->values->value) + 1);
+            unquote_string(p->values->value, buf);
+            dt_timezone = buf;
             break;
         }
     }
             break;
         }
     }
@@ -360,8 +372,11 @@ format_datetime (tzdesc_t timezones, const contentline *node) {
         if (tz->tzid  &&  ! strcasecmp (dt_timezone, tz->tzid)) { break; }
     }
 
         if (tz->tzid  &&  ! strcasecmp (dt_timezone, tz->tzid)) { break; }
     }
 
-    if (! tz) {
+    if (tz) {
+        free(dt_timezone);
+    } else {
         advise (NULL, "did not find VTIMEZONE section for %s", dt_timezone);
         advise (NULL, "did not find VTIMEZONE section for %s", dt_timezone);
+        free(dt_timezone);
         return NULL;
     }
 
         return NULL;
     }
 
index b1146cc1202900e6ba40c83613462a9d43aaf50a..d3900e05648bfbd57916ef05390148b82e4cf04e 100755 (executable)
@@ -739,4 +739,40 @@ check "$expected" "$MH_TEST_DIR/test1.txt"
 rm -f "$MH_TEST_DIR/test1.ics"
 
 
 rm -f "$MH_TEST_DIR/test1.ics"
 
 
+# Check TZID name wrapped with quotes, this used to cause a segfault.
+cat >"$expected" <<'EOF'
+Method: REQUEST
+Summary: Quoted timezone ID
+At: Wed, 01 Jan 2014 00:00
+To: Wed, 01 Jan 2014 01:00
+EOF
+
+cat >"$MH_TEST_DIR/test1.ics" <<'EOF'
+BEGIN:VCALENDAR
+PRODID:Zimbra-Calendar-Provider
+VERSION:2.0
+METHOD:REQUEST
+SUMMARY:Quoted timezone ID
+BEGIN:VTIMEZONE
+TZID:Etc/GMT
+BEGIN:STANDARD
+DTSTART:19710101T000000
+TZOFFSETTO:-0000
+TZOFFSETFROM:-0000
+TZNAME:GMT
+END:STANDARD
+END:VTIMEZONE
+BEGIN:VEVENT
+DTSTART:20140101T000000
+DTEND;TZID="Etc/GMT":20140101T010000
+SEQUENCE:0
+END:VEVENT
+END:VCALENDAR
+EOF
+
+TZ=UTC mhical <"$MH_TEST_DIR/test1.ics" >"$MH_TEST_DIR/test1.txt"
+check "$expected" "$MH_TEST_DIR/test1.txt"
+rm -f "$MH_TEST_DIR/test1.ics"
+
+
 exit $failed
 exit $failed