Fix crash in KeeShare when importing deleted share

* Fix #4895 - when KeeShare imports a database it performs a merge operation. If that share was deleted from another identical database (ie, same base group UUID), then the group would be deleted in the middle of reinit causing a crash. This fix moves the group into a QPointer catching the delete operation.
This commit is contained in:
Jonathan White 2020-10-12 16:50:13 -04:00
parent 1ed5cc9898
commit dc57025218
No known key found for this signature in database
GPG Key ID: 440FC65F2E0C6E01

View File

@ -66,7 +66,7 @@ void ShareObserver::deinitialize()
void ShareObserver::reinitialize()
{
QList<QPair<Group*, KeeShareSettings::Reference>> shares;
QList<QPair<QPointer<Group>, KeeShareSettings::Reference>> shares;
for (Group* group : m_db->rootGroup()->groupsRecursive(true)) {
auto oldReference = m_groupToReference.value(group);
auto newReference = KeeShare::referenceOf(group);
@ -97,6 +97,10 @@ void ShareObserver::reinitialize()
for (const auto& share : shares) {
auto group = share.first;
auto& reference = share.second;
// Check group validity, it may have been deleted by a merge action
if (!group) {
continue;
}
if (!reference.path.isEmpty() && reference.type != KeeShareSettings::Inactive) {
const auto newResolvedPath = resolvePath(reference.path, m_db);