From b93dc2756d9947236deb955634b499b27aaaa414 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 28 Jun 2017 16:21:01 +0200 Subject: Fix concurrent access to QBluetoothSocket::canReadLine() on Android On Android, the socket's read buffer is managed in the Java thread. QBluetoothSocket::canReadLine() is public API (most likely) being called by in the main Qt thread though. The function directly called into the Java buffer instance without proper locking. This can create race conditions. Starting with this patch canReadLine() calls another QBluetoothSocketPrivate indirection to allow a platform specific implementation. This affects WinRT, BlueZ and the dummy backend too. This is not an issue on macOS as its implementation of QBluetoothSocket is separate and does not have to deal with multiple QBluetoothSocketPrivate implementations. Task-number: QTBUG-58190 Task-number: QTBUG-60830 Change-Id: Idae19f1aee6f809699d36519b01a3c68ad9c563d Reviewed-by: Qt CI Bot Reviewed-by: Oliver Wolff --- src/bluetooth/android/inputstreamthread.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/bluetooth/android/inputstreamthread.cpp') diff --git a/src/bluetooth/android/inputstreamthread.cpp b/src/bluetooth/android/inputstreamthread.cpp index ecd9218e..982c477b 100644 --- a/src/bluetooth/android/inputstreamthread.cpp +++ b/src/bluetooth/android/inputstreamthread.cpp @@ -77,6 +77,12 @@ qint64 InputStreamThread::bytesAvailable() const return m_socket_p->buffer.size(); } +bool InputStreamThread::canReadLine() const +{ + QMutexLocker locker(&m_mutex); + return m_socket_p->buffer.canReadLine(); +} + qint64 InputStreamThread::readData(char *data, qint64 maxSize) { QMutexLocker locker(&m_mutex); -- cgit v1.2.3