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:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user