Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
Prevent overflow of numberOfOccurrencesWithinInterval
Browse files Browse the repository at this point in the history
Potentially large (quint64) value divided by a potentially small
divisor (e.g. 1 or 2) could result in a value which cannot fit into
an int, resulting in overlfow.

Also fix comment to refer to appropriate variable.
  • Loading branch information
Chris Adams committed Oct 17, 2019
1 parent de179ab commit a965fab
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions kcalcore/recurrencerule.cpp
Expand Up @@ -1771,10 +1771,12 @@ DateTimeList RecurrenceRule::timesInInterval( const KDateTime &dtStart,
}
KDateTime dt = start.addSecs( offsetFromNextOccurrence );
if ( dt <= enddt ) {
int numberOfOccurrencesWithinInterval = static_cast<int>( dt.secsTo_long( enddt ) / d->mTimedRepetition ) + 1;
// limit n by a sane value else we can "explode".
numberOfOccurrencesWithinInterval = qMin( numberOfOccurrencesWithinInterval, LOOP_LIMIT );
for ( int i = 0; i < numberOfOccurrencesWithinInterval; dt = dt.addSecs( d->mTimedRepetition ), ++i ) {
quint64 numberOfOccurrencesWithinInterval = ( dt.secsTo_long( enddt ) / d->mTimedRepetition ) + 1;
// limit numberOfOccurrencesWithinInterval by a sane value else we can "explode".
numberOfOccurrencesWithinInterval = numberOfOccurrencesWithinInterval < LOOP_LIMIT
? numberOfOccurrencesWithinInterval
: LOOP_LIMIT;
for ( quint64 i = 0; i < numberOfOccurrencesWithinInterval; dt = dt.addSecs( d->mTimedRepetition ), ++i ) {
result += dt;
}
}
Expand Down

0 comments on commit a965fab

Please sign in to comment.