calendarspec: reject open weekday ranges

Forbid open ranges like "Tue.."; trailing commas are still OK.
This commit is contained in:
Douglas Christman
2016-11-24 18:22:08 -05:00
parent 04773cb50a
commit 6bae2fd4cd
2 changed files with 15 additions and 6 deletions
+12 -6
View File
@@ -372,9 +372,6 @@ static int parse_weekdays(const char **p, CalendarSpec *c) {
for (;;) {
unsigned i;
if (!first && **p == ' ')
return 0;
for (i = 0; i < ELEMENTSOF(day_nr); i++) {
size_t skip;
@@ -430,7 +427,7 @@ static int parse_weekdays(const char **p, CalendarSpec *c) {
return -EINVAL;
l = day_nr[i].nr;
*p += 1;
*p += 2;
/* Support ranges with "-" for backwards compatibility */
} else if (**p == '-') {
@@ -438,10 +435,19 @@ static int parse_weekdays(const char **p, CalendarSpec *c) {
return -EINVAL;
l = day_nr[i].nr;
} else
*p += 1;
} else if (**p == ',') {
l = -1;
*p += 1;
}
/* Allow a trailing comma but not an open range */
if (**p == 0 || **p == ' ') {
*p += strspn(*p, " ");
return l < 0 ? 0 : -EINVAL;
}
*p += 1;
first = false;
}
}