Bug 1555646 - Update libical from upstream. r=philipp
authorGeoff Lankow <geoff@darktrojan.net>
Fri, 07 Jun 2019 20:43:14 +1200
changeset 35830 b27953c5a381358c0480d73971a5c91adabecb1e
parent 35829 e48bbc985397423402a45e5fbf0b63b46e7470cf
child 35831 323c1caa59c5d6e13a9dfb9cd318fe9a6c459774
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersphilipp
bugs1555646
Bug 1555646 - Update libical from upstream. r=philipp Copied from https://github.com/libical/libical/commit/53e68ff6e2133c54ff44df53e8b75ef21125fb3d
calendar/libical/src/libical/icalparser.c
--- a/calendar/libical/src/libical/icalparser.c
+++ b/calendar/libical/src/libical/icalparser.c
@@ -963,31 +963,96 @@ icalcomponent* icalparser_add_line(icalp
 		icalmemory_free_buffer(str);
 		str = NULL;
   	  	
 		continue;
 	    }
 
 	    /* If it is a VALUE parameter, set the kind of value*/
 	    if (icalparameter_isa(param)==ICAL_VALUE_PARAMETER){
+        const char unknown_type[] =
+            "Got a VALUE parameter with an unknown type";
+        const char illegal_type[] =
+            "Got a VALUE parameter with an illegal type for property";
+        const char *value_err = NULL;
+
 
 		value_kind = (icalvalue_kind)
                     icalparameter_value_to_value_kind(
                                 icalparameter_get_value(param)
                                 );
 
 		if (value_kind == ICAL_NO_VALUE){
 
 		    /* Ooops, could not parse the value of the
 		       parameter ( it was not one of the defined
 		       values ), so reset the value_kind */
-			
-		    insert_error(
-			tail, str, 
-			"Got a VALUE parameter with an unknown type",
+
+        value_err = unknown_type;
+    }
+    else if (value_kind !=
+             icalproperty_kind_to_value_kind(icalproperty_isa(prop))) {
+        /* VALUE parameter type does not match default type
+           for this property (check for allowed alternate types) */
+
+        switch (prop_kind) {
+        case ICAL_ATTACH_PROPERTY:
+        // case ICAL_IMAGE_PROPERTY:
+            /* Accept BINARY */
+            if (value_kind != ICAL_BINARY_VALUE)
+                value_err = illegal_type;
+            break;
+
+        case ICAL_DTEND_PROPERTY:
+        case ICAL_DUE_PROPERTY:
+        case ICAL_DTSTART_PROPERTY:
+        case ICAL_EXDATE_PROPERTY:
+        case ICAL_RECURRENCEID_PROPERTY:
+            /* Accept DATE */
+            if (value_kind != ICAL_DATE_VALUE)
+                value_err = illegal_type;
+            break;
+
+        case ICAL_GEO_PROPERTY:
+            /* Accept FLOAT (but change to GEO) */
+            if (value_kind != ICAL_FLOAT_VALUE)
+                value_err = illegal_type;
+            else value_kind = ICAL_GEO_VALUE;
+            break;
+
+        case ICAL_RDATE_PROPERTY:
+            /* Accept DATE-TIME, DATE or PERIOD */
+            if (value_kind != ICAL_DATETIME_VALUE &&
+                value_kind != ICAL_DATE_VALUE &&
+                value_kind != ICAL_PERIOD_VALUE)
+                value_err = illegal_type;
+            break;
+
+        case ICAL_TRIGGER_PROPERTY:
+            /* Accept DATE-TIME */
+            if (value_kind != ICAL_DATETIME_VALUE)
+                value_err = illegal_type;
+            break;
+
+        case ICAL_X_PROPERTY:
+            /* Accept ANY value type */
+            break;
+
+        default:
+            /* ONLY default type is allowed */
+            value_err = illegal_type;
+            break;
+        }
+    }
+
+    if (value_err != NULL) {
+        /* Ooops, unknown/illegal VALUE parameter,
+           so reset the value_kind */
+
+        insert_error(tail, str, value_err,
 			ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR);
 			
 		    value_kind = 
 			icalproperty_kind_to_value_kind(
 			    icalproperty_isa(prop));
 			
 		    icalparameter_free(param);
 		    tail = 0;