Revert "Add qt_safe_ftok wrapper for ftok"

This reverts commit ac0184d608. That
commit added the use of qHash in qt_safe_ftok, which made ftok even more
unsafe than previously. Since the algorithm in qHash can change across
Qt versions, we need a stable algorithm instead.

[ChangeLog][Important Behavior Changes] Reverted a change that caused Qt
5.6 through 5.8 not to connect to QSystemSemaphore and QSharedMemory
created by running applications using Qt earlier than
5.6. Unfortunately, this means that Qt 5.9 will not connect to 5.6-5.8.

Task-number: QTBUG-60771
Change-Id: Ibc3472e1c11d46358357fffd14bf51aeb48ef2c8
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
bb10
Thiago Macieira 2017-05-16 23:40:15 -07:00 committed by Lars Knoll
parent fc874c2976
commit 9406bef6b3
4 changed files with 6 additions and 16 deletions

4
dist/changes-5.9.0 vendored
View File

@ -32,6 +32,10 @@ information about a particular change.
- [QTBUG-59849] QSysInfo::productType() and QFileSelector behavior on
macOS was restored to match what Qt used to return in version 5.7.0 and
earlier. The behavior found in Qt 5.6.2, 5.7.1 and 5.8.0 is removed.
- [QTBUG-60771] Reverted a change that caused Qt 5.6 through 5.8 not to
connect to QSystemSemaphore and QSharedMemory created by running
applications using Qt earlier than 5.6. Unfortunately, this means that Qt
5.9 will not connect to 5.6-5.8.
- QTouchEvent
* Touch point ids are now unique even between different devices. As a

View File

@ -55,7 +55,6 @@
#include <QtCore/private/qglobal_p.h>
#include "qplatformdefs.h"
#include "qatomic.h"
#include "qhash.h"
#ifndef Q_OS_UNIX
# error "qcore_unix_p.h included on a non-Unix system"
@ -369,19 +368,6 @@ union qt_semun {
unsigned short *array; /* array for GETALL, SETALL */
};
#ifndef QT_POSIX_IPC
#if QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore)
#ifndef Q_OS_ANDROID
static inline key_t qt_safe_ftok(const QByteArray &filename, int proj_id)
{
// Unfortunately ftok can return colliding keys even for different files.
// Try to add some more entropy via qHash.
return ::ftok(filename.constData(), qHash(filename, proj_id));
}
#endif // !Q_OS_ANDROID
#endif // QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore)
#endif // !QT_POSIX_IPC
QT_END_NAMESPACE
#endif

View File

@ -88,7 +88,7 @@ key_t QSharedMemoryPrivate::handle()
return 0;
}
unix_key = qt_safe_ftok(QFile::encodeName(nativeKey), 'Q');
unix_key = ftok(QFile::encodeName(nativeKey).constData(), 'Q');
if (-1 == unix_key) {
errorString = QSharedMemory::tr("%1: ftok failed").arg(QLatin1String("QSharedMemory::handle:"));
error = QSharedMemory::KeyError;

View File

@ -104,7 +104,7 @@ key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode)
#if !defined(QT_NO_SHAREDMEMORY) && !defined(QT_POSIX_IPC) && !defined(Q_OS_ANDROID)
// Get the unix key for the created file
unix_key = qt_safe_ftok(QFile::encodeName(fileName), 'Q');
unix_key = ftok(QFile::encodeName(fileName).constData(), 'Q');
#endif
if (-1 == unix_key) {
errorString =