Merge pull request #512 from ispyisail/fix-492-backup-uaf

Although I haven’t encountered the problems described myself (nor do I need to!), the changes and additions look plausible and compile without errors or warnings, so I’m approving this PR!

But as a remark:
I'm not particularly familiar with the Qt functions used here. But when I see that there is a version-specific implementation for Qt5 and only a debug-message mentioned for Qt6, it makes me wonder:
Is it implemented differently there, or is it not even needed there — which I don't think is the case...
If possible, "we" should also include something for Qt6 and later versions in another PR.
Do you know what’s needed for Qt6, @ispyisail ?
This commit is contained in:
plc-user
2026-06-19 12:35:47 +02:00
committed by GitHub
2 changed files with 14 additions and 1 deletions
+12 -1
View File
@@ -137,6 +137,11 @@ QETProject::QETProject(KAutoSaveFile *backup, QObject *parent) :
*/
QETProject::~QETProject()
{
//Wait for any in-flight async crash-recovery backup to finish: the worker
//writes through &m_backup_file, a member that would otherwise be destroyed
//under it (issue #492).
m_backup_future.waitForFinished();
//We block database signal to avoid hundreds of unnecessary emitted signal
//due to deletion (diagram, item, etc...) and as much update made in the not yet deleted things.
m_data_base.blockSignals(true);
@@ -339,6 +344,8 @@ void QETProject::setFilePath(const QString &filepath)
}
#ifdef BUILD_WITHOUT_KF5
#else
//Don't close/re-point the backup file while a backup is still writing it.
m_backup_future.waitForFinished();
if (m_backup_file.isOpen()) {
m_backup_file.close();
}
@@ -1809,8 +1816,12 @@ void QETProject::writeBackup()
#ifdef BUILD_WITHOUT_KF5
#else
# if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
//Don't launch a new backup while the previous one is still writing:
//both would write through &m_backup_file on different threads.
if (m_backup_future.isRunning())
return;
QDomDocument xml_project(toXml());
QtConcurrent::run(
m_backup_future = QtConcurrent::run(
QET::writeToFile,xml_project,&m_backup_file,nullptr);
# else
# if TODO_LIST
+2
View File
@@ -35,6 +35,7 @@
#endif
#include <QHash>
#include <QFuture>
class Diagram;
class ElementsLocation;
@@ -295,6 +296,7 @@ class QETProject : public QObject
bool m_freeze_new_conductors = false;
QTimer m_save_backup_timer,
m_autosave_timer;
QFuture<bool> m_backup_future;
#ifdef BUILD_WITHOUT_KF5
#else
KAutoSaveFile m_backup_file;