diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-06-14 18:10:15 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-06-16 15:53:23 +0200 |
commit | 9661cde1615e21f5b6bbffe3e687cacba247f514 (patch) | |
tree | 59c87f748cf2fce86a6b8a1ab8e3d4dfdc71e071 /tests/auto/corelib | |
parent | 20f835329a35651c720b73a8d217e3b48ebd2fcf (diff) |
Apple: Use POSIX IPC instead of System V in sandboxed applications
System V semaphores are not supported in sandboxed applications,
so when Qt is configured with App Store compliance, or the user
requests POSIX IPC explicitly, we use that instead.
https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/doc/uid/TP40011183-CH3-SW24
As the shared memory name limit on Apple platforms is very low,
we have to skip the existing logic for naming, and instead use
a truncated hash of the key. This should still be fine for
avoiding any collisions in practice.
An explicit check for the ENAMETOOLONG error has been added to
catch any cases where they key goes beyond the allowed length.
Sandboxed applications also have an extra requirement that the
key must include an application group identifier. This requirement
has been pushed up to the user and documented, as we don't have
enough information in Qt to know which identifier to use.
Both tst_QSystemSemaphore and tst_QSharedMemory work as before
with both sandboxed and non-sandboxed applications, after removing
some assumptions in tst_QSharedMemory about System V behavior.
Fixes: QTBUG-91130
Change-Id: Iaf1edb36a5d84d69e42ec31471a48d112faa8c6a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/kernel/qsharedmemory/tst_qsharedmemory.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/tests/auto/corelib/kernel/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/corelib/kernel/qsharedmemory/tst_qsharedmemory.cpp index 31b9c9740a..81a7dcf36f 100644 --- a/tests/auto/corelib/kernel/qsharedmemory/tst_qsharedmemory.cpp +++ b/tests/auto/corelib/kernel/qsharedmemory/tst_qsharedmemory.cpp @@ -182,14 +182,15 @@ int tst_QSharedMemory::remove(const QString &key) if (key.isEmpty()) return -1; - // ftok requires that an actual file exists somewhere QString fileName = QSharedMemoryPrivate::makePlatformSafeKey(key); + +#ifndef QT_POSIX_IPC + // ftok requires that an actual file exists somewhere if (!QFile::exists(fileName)) { //qDebug() << "exits failed"; return -2; } -#ifndef QT_POSIX_IPC int unix_key = ftok(fileName.toLatin1().constData(), 'Q'); if (-1 == unix_key) { qDebug() << "ftok failed"; @@ -209,8 +210,10 @@ int tst_QSharedMemory::remove(const QString &key) } #else if (shm_unlink(QFile::encodeName(fileName).constData()) == -1) { - qDebug() << "shm_unlink failed"; - return -5; + if (errno != ENOENT) { + qDebug() << "shm_unlink failed"; + return -5; + } } #endif // QT_POSIX_IPC @@ -374,7 +377,7 @@ void tst_QSharedMemory::lock() QVERIFY(!shm.lock()); QCOMPARE(shm.error(), QSharedMemory::LockError); - shm.setKey(QLatin1String("qsharedmemory")); + shm.setKey(rememberKey(QLatin1String("qsharedmemory"))); QVERIFY(!shm.lock()); QCOMPARE(shm.error(), QSharedMemory::LockError); @@ -411,6 +414,11 @@ void tst_QSharedMemory::removeWhileAttached() delete smOne; delete smTwo; +#ifdef QT_POSIX_IPC + // POSIX IPC doesn't guarantee that the shared memory is removed + remove("one"); +#endif + // three shouldn't be able to attach QSharedMemory smThree(QLatin1String("one")); QVERIFY(!smThree.attach()); @@ -580,6 +588,10 @@ void tst_QSharedMemory::simpleDoubleProducerConsumer() int size = 512; QVERIFY(producer.create(size)); QVERIFY(producer.detach()); +#ifdef QT_POSIX_IPC + // POSIX IPC doesn't guarantee that the shared memory is removed + remove("market"); +#endif QVERIFY(producer.create(size)); { |