recur: Prevent infinite loops with 0 periods

Specifying a recurrence interval that amounts to a zero, like 'P0M', 0q
or 0m causes task to fall into an infinite loop when trying to determine
next recurrence dates.

Detect scenarios with zero-length recurrence interval and throw an
exception.

Closes #2262.
This commit is contained in:
Tomas Babej 2020-12-06 20:49:35 -05:00
parent ccb222a31b
commit fcfe01f301
No known key found for this signature in database
GPG key ID: B0747C6578F7D2F5

View file

@ -234,6 +234,9 @@ Datetime getNextRecurrence (Datetime& current, std::string& period)
{
int increment = strtol (period.substr (0, period.length () - 1).c_str (), nullptr, 10);
if (increment <= 0)
throw format ("Recurrence period '{1}' is equivalent to {2} and hence invalid.", period, increment);
m += increment;
while (m > 12)
{
@ -253,6 +256,9 @@ Datetime getNextRecurrence (Datetime& current, std::string& period)
{
int increment = strtol (period.substr (1, period.length () - 2).c_str (), nullptr, 10);
if (increment <= 0)
throw format ("Recurrence period '{1}' is equivalent to {2} and hence invalid.", period, increment);
m += increment;
while (m > 12)
{
@ -286,6 +292,9 @@ Datetime getNextRecurrence (Datetime& current, std::string& period)
{
int increment = strtol (period.substr (0, period.length () - 1).c_str (), nullptr, 10);
if (increment <= 0)
throw format ("Recurrence period '{1}' is equivalent to {2} and hence invalid.", period, increment);
m += 3 * increment;
while (m > 12)
{