From 8f1277da8c137270ff857128d8fea1423d8a7700 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 22 Oct 2017 21:39:31 +0200 Subject: QStorageInfo: Properly decode labels from /dev/disk/by-label udev encodes the labels for /dev/disk/by-label/ with ID_LABEL_FS_ENC which is done with blkid_encode_string(). This function encodes some unsafe 1-byte utf-8 characters as hex (e.g. '\' or ' ') Task-number: QTBUG-61420 Change-Id: If82f4381d348acf9008b79ec5ac7c55e6d3819de Reviewed-by: Thiago Macieira --- src/corelib/io/qstorageinfo_unix.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp index 9072b34f54..1fc32e0f2d 100644 --- a/src/corelib/io/qstorageinfo_unix.cpp +++ b/src/corelib/io/qstorageinfo_unix.cpp @@ -544,6 +544,38 @@ void QStorageInfoPrivate::initRootPath() } } +#ifdef Q_OS_LINUX +// udev encodes the labels with ID_LABEL_FS_ENC which is done with +// blkid_encode_string(). Within this function some 1-byte utf-8 +// characters not considered safe (e.g. '\' or ' ') are encoded as hex +static QString decodeFsEncString(const QString &str) +{ + QString decoded; + decoded.reserve(str.size()); + + int i = 0; + while (i < str.size()) { + if (i <= str.size() - 4) { // we need at least four characters \xAB + if (str.at(i) == QLatin1Char('\\') && + str.at(i+1) == QLatin1Char('x')) { + bool bOk; + const int code = str.midRef(i+2, 2).toInt(&bOk, 16); + // only decode characters between 0x20 and 0x7f but not + // the backslash to prevent collisions + if (bOk && code >= 0x20 && code < 0x80 && code != '\\') { + decoded += QChar(code); + i += 4; + continue; + } + } + } + decoded += str.at(i); + ++i; + } + return decoded; +} +#endif + static inline QString retrieveLabel(const QByteArray &device) { #ifdef Q_OS_LINUX @@ -557,7 +589,7 @@ static inline QString retrieveLabel(const QByteArray &device) it.next(); QFileInfo fileInfo(it.fileInfo()); if (fileInfo.isSymLink() && fileInfo.symLinkTarget() == devicePath) - return fileInfo.fileName(); + return decodeFsEncString(fileInfo.fileName()); } #elif defined Q_OS_HAIKU fs_info fsInfo; -- cgit v1.2.3 From 851c226247d692a608d78a1d7f9e621f4a82f40d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 2 Nov 2017 08:56:09 +0100 Subject: QFilesystemWatcher/Windows: Use event dispatcher of thread Previously, the native event filter listening on removable drivers was installed on QCoreApplication::eventDispatcher() which led to a mismatch when launched from a non-GUI thread since ~QAbstractNativeEventFilter() removes itself from QAbstractEventDispatcher::instance(). Amends 45580aa92557caa4f3f5be783573ddb80602e494, e612fe8d47bc0fe762668617a5189117ad1aee15. Task-number: QTBUG-64171 Change-Id: Icbe289bd585f124d66989d0cd574040b986e680c Reviewed-by: Thiago Macieira --- src/corelib/io/qfilesystemwatcher_win.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index cdb79e7c97..9e43d11e71 100644 --- a/src/corelib/io/qfilesystemwatcher_win.cpp +++ b/src/corelib/io/qfilesystemwatcher_win.cpp @@ -308,7 +308,7 @@ void QWindowsRemovableDriveListener::addPath(const QString &p) notify.dbch_size = sizeof(notify); notify.dbch_devicetype = DBT_DEVTYP_HANDLE; notify.dbch_handle = volumeHandle; - QEventDispatcherWin32 *winEventDispatcher = static_cast(QCoreApplication::eventDispatcher()); + QEventDispatcherWin32 *winEventDispatcher = static_cast(QAbstractEventDispatcher::instance()); re.devNotify = RegisterDeviceNotification(winEventDispatcher->internalHwnd(), ¬ify, DEVICE_NOTIFY_WINDOW_HANDLE); // Empirically found: The notifications also work when the handle is immediately @@ -336,7 +336,7 @@ QWindowsFileSystemWatcherEngine::QWindowsFileSystemWatcherEngine(QObject *parent : QFileSystemWatcherEngine(parent) { #ifndef Q_OS_WINRT - if (QAbstractEventDispatcher *eventDispatcher = QCoreApplication::eventDispatcher()) { + if (QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance()) { m_driveListener = new QWindowsRemovableDriveListener(this); eventDispatcher->installNativeEventFilter(m_driveListener); parent->setProperty("_q_driveListener", -- cgit v1.2.3