mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
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:
parent
ccb222a31b
commit
fcfe01f301
1 changed files with 9 additions and 0 deletions
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue