From 81dabe5ace3091656cdbac57598699bb3b9beea7 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 27 Jun 2017 13:50:19 +0200 Subject: Fix incorrect uuid check due to temporary char* in QString::toUtf8() toUtf8() creates a temporary char* representation which is assigned to uuid. As soon the object created by toUtf8() gets destroyed, the uuid pointer points to releases memory. The intention is to check that we don't have one of the standard 16bit Bluetooth uuids. That's the purpose of QBluetoothUuid::toUInt16(). Signed-off-by: Alex Blasche Signed-off-by: Linus Torvalds --- core/qt-ble.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp index 06adce63a..bed5f5feb 100644 --- a/core/qt-ble.cpp +++ b/core/qt-ble.cpp @@ -42,13 +42,14 @@ void BLEObject::writeCompleted(const QLowEnergyDescriptor &d, const QByteArray & void BLEObject::addService(const QBluetoothUuid &newService) { - const char *uuid = newService.toString().toUtf8().data(); - - qDebug() << "Found service" << uuid; - if (uuid[1] == '0') { - qDebug () << " .. ignoring since first digit is '0'"; + qDebug() << "Found service" << newService; + bool isStandardUuid = false; + newService.toUInt16(&isStandardUuid); + if (isStandardUuid) { + qDebug () << " .. ignoring standard service"; return; } + service = controller->createServiceObject(newService, this); qDebug() << " .. created service object" << service; if (service) { -- cgit v1.2.3-70-g09d2