From 6f5f600559de391e53617b6612d7e3ed8bf00b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20V=C3=A4nttinen?= Date: Tue, 24 Oct 2023 06:08:41 +0300 Subject: [PATCH] Fix crash on database open from browser (#9939) --- src/browser/BrowserService.cpp | 2 +- src/gui/DatabaseTabWidget.cpp | 9 ++++++++- src/gui/DatabaseTabWidget.h | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/browser/BrowserService.cpp b/src/browser/BrowserService.cpp index 406276182..cff27209a 100644 --- a/src/browser/BrowserService.cpp +++ b/src/browser/BrowserService.cpp @@ -116,7 +116,7 @@ bool BrowserService::openDatabase(bool triggerUnlock) return true; } - if (triggerUnlock) { + if (triggerUnlock && !m_bringToFrontRequested) { m_bringToFrontRequested = true; updateWindowState(); emit requestUnlock(); diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index d4e50116f..4e422ebb2 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 KeePassXC Team + * Copyright (C) 2023 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,6 +41,7 @@ DatabaseTabWidget::DatabaseTabWidget(QWidget* parent) , m_dbWidgetStateSync(new DatabaseWidgetStateSync(this)) , m_dbWidgetPendingLock(nullptr) , m_databaseOpenDialog(new DatabaseOpenDialog(this)) + , m_databaseOpenInProgress(false) { auto* tabBar = new QTabBar(this); tabBar->setAcceptDrops(true); @@ -857,6 +858,7 @@ void DatabaseTabWidget::emitDatabaseLockChanged() emit databaseLocked(dbWidget); } else { emit databaseUnlocked(dbWidget); + m_databaseOpenInProgress = false; } } @@ -889,6 +891,11 @@ void DatabaseTabWidget::performGlobalAutoType(const QString& search) void DatabaseTabWidget::performBrowserUnlock() { + if (m_databaseOpenInProgress) { + return; + } + + m_databaseOpenInProgress = true; auto dbWidget = currentDatabaseWidget(); if (dbWidget && dbWidget->isLocked()) { unlockAnyDatabaseInDialog(DatabaseOpenDialog::Intent::Browser); diff --git a/src/gui/DatabaseTabWidget.h b/src/gui/DatabaseTabWidget.h index 3a6791a80..58f5408e3 100644 --- a/src/gui/DatabaseTabWidget.h +++ b/src/gui/DatabaseTabWidget.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 KeePassXC Team + * Copyright (C) 2023 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -117,6 +117,7 @@ private: QPointer m_dbWidgetPendingLock; QPointer m_databaseOpenDialog; QTimer m_lockDelayTimer; + bool m_databaseOpenInProgress; }; #endif // KEEPASSX_DATABASETABWIDGET_H