From 4edb623745a925bb96df0fab93bb87b2f6dec64f Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Fri, 8 Nov 2019 18:05:37 -0500 Subject: [PATCH] Prevent recursive loads using AutoOpen * Fix #3334 - AutoOpen is now processed after the database widget is put into view mode to prevent infinite recursion of unlock attempts if two databases auto open each other. --- src/core/Global.h | 6 ++++++ src/gui/DatabaseTabWidget.cpp | 3 ++- src/gui/DatabaseWidget.cpp | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/core/Global.h b/src/core/Global.h index 64570b33b..9ebe78790 100644 --- a/src/core/Global.h +++ b/src/core/Global.h @@ -36,6 +36,12 @@ #define QUINT32_MAX 4294967295U #endif +#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) +#define FILE_CASE_SENSITIVE Qt::CaseInsensitive +#else +#define FILE_CASE_SENSITIVE Qt::CaseSensitive +#endif + template struct AddConst { typedef const T Type; diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index 4c8458e52..9cbfa8fd7 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -156,6 +156,7 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath, { QFileInfo fileInfo(filePath); QString canonicalFilePath = fileInfo.canonicalFilePath(); + if (canonicalFilePath.isEmpty()) { emit messageGlobal(tr("Failed to open %1. It either does not exist or is not accessible.").arg(filePath), MessageWidget::Error); @@ -165,7 +166,7 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath, for (int i = 0, c = count(); i < c; ++i) { auto* dbWidget = databaseWidgetFromIndex(i); Q_ASSERT(dbWidget); - if (dbWidget && dbWidget->database()->canonicalFilePath() == canonicalFilePath) { + if (dbWidget && dbWidget->database()->canonicalFilePath().compare(canonicalFilePath, FILE_CASE_SENSITIVE) == 0) { dbWidget->performUnlockDatabase(password, keyfile); if (!inBackground) { // switch to existing tab if file is already open diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index a8e6b4274..54f2a2f47 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -400,7 +400,6 @@ void DatabaseWidget::replaceDatabase(QSharedPointer db) m_db = std::move(db); connectDatabaseSignals(); m_groupView->changeDatabase(m_db); - processAutoOpen(); // Restore the new parent group pointer, if not found default to the root group // this prevents data loss when merging a database while creating a new entry @@ -946,6 +945,7 @@ void DatabaseWidget::loadDatabase(bool accepted) if (accepted) { replaceDatabase(openWidget->database()); switchToMainView(); + processAutoOpen(); m_saveAttempts = 0; emit databaseUnlocked(); if (config()->get("MinimizeAfterUnlock").toBool()) { @@ -1032,6 +1032,7 @@ void DatabaseWidget::unlockDatabase(bool accepted) m_entryBeforeLock = QUuid(); switchToMainView(); + processAutoOpen(); emit databaseUnlocked(); if (senderDialog && senderDialog->intent() == DatabaseOpenDialog::Intent::AutoType) { @@ -1468,6 +1469,7 @@ void DatabaseWidget::reloadDatabaseFile() } replaceDatabase(db); + processAutoOpen(); restoreGroupEntryFocus(groupBeforeReload, entryBeforeReload); m_blockAutoSave = false; } else {