summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
diff options
context:
space:
mode:
authorMate Barany <mate.barany@qt.io>2023-01-13 18:18:08 +0100
committerMate Barany <mate.barany@qt.io>2023-02-08 12:59:19 +0100
commit84f0596c0ca7cb5a31077cea29592781899c13f4 (patch)
treea4271a3d74a9fab51b0de3c692ebf323d13d28b3 /tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
parent214c3a033a4e9191f0082bf6f88624d356a45384 (diff)
Avoid potential data races caused by qt_ntfs_permission_lookup
qt_ntfs_permission_lookup is a global, non-atomic variable which could cause problems in case of multiple threads. Introduce a new atomic variable to handle permission lookups but instead of manual incrementation/decrementation, implement a class to manage the variable. Since the atomic variable is not directly available to the user, implement helper functions to increase/decrease/check the status of the variable. Task-number: QTBUG-105804 Change-Id: If6cbcdd653c7f50ad9853a5c309e24fdeb520788 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp')
-rw-r--r--tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp12
1 files changed, 2 insertions, 10 deletions
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
index 485d5792ac..abd4dfed5e 100644
--- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
@@ -4,7 +4,6 @@
#include <QTest>
#include <QStandardPaths>
#include <QScopeGuard>
-#include <QScopedValueRollback>
#include <qfile.h>
#include <qdir.h>
@@ -43,9 +42,6 @@
#endif
#if defined(Q_OS_WIN)
-QT_BEGIN_NAMESPACE
-extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
-QT_END_NAMESPACE
bool IsUserAdmin();
#endif
@@ -1905,8 +1901,7 @@ void tst_QFileInfo::isWritable()
#endif
#if defined (Q_OS_WIN)
- QScopedValueRollback<int> ntfsMode(qt_ntfs_permission_lookup);
- qt_ntfs_permission_lookup = 1;
+ QNtfsPermissionCheckGuard permissionGuard;
QFileInfo fi2(QFile::decodeName(qgetenv("SystemRoot") + "/system.ini"));
QVERIFY(fi2.exists());
QCOMPARE(fi2.isWritable(), IsUserAdmin());
@@ -2156,7 +2151,7 @@ void tst_QFileInfo::owner()
NetApiBufferFree(pBuf);
}
}
- qt_ntfs_permission_lookup = 1;
+ QNtfsPermissionCheckGuard permissionGuard;
#endif
if (userName.isEmpty())
QSKIP("Can't retrieve the user name");
@@ -2173,9 +2168,6 @@ void tst_QFileInfo::owner()
QCOMPARE(fi.owner(), userName);
QFile::remove(fileName);
-#if defined(Q_OS_WIN)
- qt_ntfs_permission_lookup = 0;
-#endif
}
void tst_QFileInfo::group()