Bug 1553808 - Update libical from upstream. r=philipp
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 05 Jun 2019 14:18:14 +1200
changeset 35827 9605974b295d9fc51e196c928ff9895818efd398
parent 35826 02a09c7cc1e384140f9675a9aa3048485f13c519
child 35828 bab0908888b8a7f8399a440bbc345b3d895d68c4
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersphilipp
bugs1553808
Bug 1553808 - Update libical from upstream. r=philipp
calendar/libical/src/libical/icalrecur.c
--- a/calendar/libical/src/libical/icalrecur.c
+++ b/calendar/libical/src/libical/icalrecur.c
@@ -399,20 +399,25 @@ void icalrecur_add_bydayrules(struct ica
 	/* Outlook/Exchange generate "BYDAY=MO, FR" and "BYDAY=2 TH".
 	 * Cope with that.
 	 */
 	if (*t == ' ')
 	    t++;
 
 	wd = icalrecur_string_to_weekday(t);
 
-        if (wd != ICAL_NO_WEEKDAY) {
-            array[i++] = (short) (sign * (wd + 8 * weekno));
-            array[i] = ICAL_RECURRENCE_ARRAY_MAX;
+        /* Sanity check value */
+        if (wd == ICAL_NO_WEEKDAY || weekno >= ICAL_BY_WEEKNO_SIZE) {
+            free(vals_copy);
+            return;
         }
+
+        int position = sign * weekno;
+        array[i++] = (wd + (8 * abs(position))) * ((position < 0) ? -1 : 1);
+        array[i] = ICAL_RECURRENCE_ARRAY_MAX;
     }
 
     free(vals_copy);
 
     sort_bydayrules(parser->rt.by_day, parser->rt.week_start);
 }