Skip to content

Commit

Permalink
[kf5-calendarcore] Avoid using forIncidences() template in MemoryCale…
Browse files Browse the repository at this point in the history
…ndar::deleteIncidenceInstances(). JB#47814
  • Loading branch information
blammit committed Dec 18, 2020
1 parent 786b360 commit 7d1ee79
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
@@ -0,0 +1,44 @@
From cdc65b0c4fd5e76e97a5e732b4bd2e7f953c39a2 Mon Sep 17 00:00:00 2001
From: Bea Lam <bea.lam@jolla.com>
Date: Thu, 17 Dec 2020 16:16:15 +1000
Subject: [PATCH] Avoid forIncidences() template in deleteIncidenceInstances()

This causes the incidences list to be modified by deleteIncidence()
during the loop, which can cause a crash.
---
src/memorycalendar.cpp | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/memorycalendar.cpp b/src/memorycalendar.cpp
index 78e3665a9..ef1546c4f 100644
--- a/src/memorycalendar.cpp
+++ b/src/memorycalendar.cpp
@@ -240,16 +240,19 @@ bool MemoryCalendar::deleteIncidence(const Incidence::Ptr &incidence)

bool MemoryCalendar::deleteIncidenceInstances(const Incidence::Ptr &incidence)
{
- d->forIncidences<Incidence>(d->mIncidences[incidence->type()], incidence->uid(), [this](const Incidence::Ptr &incidence) {
- if (incidence->hasRecurrenceId()) {
+ auto instances = d->mIncidences[incidence->type()];
+ auto end = instances.cend();
+ for (auto it = instances.constFind(incidence->uid()); it != end && it.key() == incidence->uid(); ++it) {
+ if (it.value()->hasRecurrenceId()) {
qCDebug(KCALCORE_LOG) << "deleting child"
- << ", type=" << int(incidence->type())
- << ", uid=" << incidence->uid()
+ << ", type=" << int(it.value()->type())
+ << ", uid=" << it.value()->uid()
// << ", start=" << i->dtStart()
<< " from calendar";
- deleteIncidence(incidence);
+
+ deleteIncidence(it.value());
}
- });
+ }

return true;
}
--
2.24.3 (Apple Git-128)

1 change: 1 addition & 0 deletions rpm/kf5-calendarcore.spec
Expand Up @@ -17,6 +17,7 @@ BuildRequires: extra-cmake-modules >= 5.75.0
Patch1: 0001-Use-UTC-times-when-calculating-the-transition-dates-.patch
Patch2: 0002-Adjust-for-lower-Qt-versions.patch
Patch3: 0003-Add-pkgconfig-packaging.patch
Patch4: 0004-Avoid-forIncidences-template-in-deleteIncidenceInsta.patch

%description
KDE Framework calendar core library
Expand Down

0 comments on commit 7d1ee79

Please sign in to comment.