diff options
author | Douglas Christman <DouglasChristman@gmail.com> | 2016-11-22 12:57:07 -0500 |
---|---|---|
committer | Douglas Christman <DouglasChristman@gmail.com> | 2016-11-23 12:28:00 -0500 |
commit | f6e7d66b9f1db07ae80af3d75dabaf95f7f43a15 (patch) | |
tree | cd6fdc2233808565aaea9e75b5817d71c28f3a47 /src/basic | |
parent | fadc06bb8166b7ee494ed90b054f083ac4db4e11 (diff) |
calendarspec: add upper bound on year
Stop looking for matches after MAX_YEAR so impossible dates like
"*-02-30" and "*-04-31" don't cause an infinite loop.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/calendarspec.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c index fda293fcb9..2fc5ceb421 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -34,6 +34,8 @@ /* Longest valid date/time range is 1970..2199 */ #define MAX_RANGE_LEN 230 +#define MIN_YEAR 1970 +#define MAX_YEAR 2199 #define BITS_WEEKDAYS 127 static void free_chain(CalendarComponent *c) { @@ -169,7 +171,7 @@ _pure_ bool calendar_spec_valid(CalendarSpec *c) { if (c->weekdays_bits > BITS_WEEKDAYS) return false; - if (!chain_valid(c->year, 1970, 2199)) + if (!chain_valid(c->year, MIN_YEAR, MAX_YEAR)) return false; if (!chain_valid(c->month, 1, 12)) @@ -1017,6 +1019,14 @@ static bool tm_out_of_bounds(const struct tm *tm, bool utc) { if (mktime_or_timegm(&t, utc) == (time_t) -1) return true; + /* + * Set an upper bound on the year so impossible dates like "*-02-31" + * don't cause find_next() to loop forever. tm_year contains years + * since 1900, so adjust it accordingly. + */ + if (tm->tm_year + 1900 > MAX_YEAR) + return true; + /* Did any normalization take place? If so, it was out of bounds before */ return t.tm_year != tm->tm_year || |