From b14984f1dd49a3a4c6054755b44e06e577f20b0f Mon Sep 17 00:00:00 2001 From: Oliver Toth Date: Wed, 15 Jun 2022 21:30:42 +0200 Subject: [PATCH] [BLE] Handle invalid character in BLE name --- src/MPDeviceBleImpl.cpp | 10 ++++++++-- src/WSServerCon.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/MPDeviceBleImpl.cpp b/src/MPDeviceBleImpl.cpp index 92221f9d..7d925a53 100644 --- a/src/MPDeviceBleImpl.cpp +++ b/src/MPDeviceBleImpl.cpp @@ -1906,8 +1906,14 @@ void MPDeviceBleImpl::getBleName(const MessageHandlerCbData &cb) connect(jobs, &AsyncJobs::finished, [this, cb](const QByteArray &data) { Q_UNUSED(data); - /* Callback */ - cb(true, "", bleProt->getFullPayload(data)); + QByteArray bleNameArr = bleProt->getFullPayload(data); + if (ZERO_BYTE == bleNameArr[0] || static_cast(0xFF) == bleNameArr[0]) + { + // Handle invalid character in BLE name (starts with 0x00 or 0xFF) + bleNameArr = DEFAULT_BLE_NAME.toUtf8(); + qWarning() << "Invalid character in BLE name"; + } + cb(true, "", bleNameArr); }); mpDev->enqueueAndRunJob(jobs); diff --git a/src/WSServerCon.cpp b/src/WSServerCon.cpp index 50fc49cd..5d5fc89f 100644 --- a/src/WSServerCon.cpp +++ b/src/WSServerCon.cpp @@ -1564,7 +1564,7 @@ void WSServerCon::processMessageBLE(QJsonObject root, const MPDeviceProgressCb & } else if (root["msg"] == "get_ble_name") { - bleImpl->getBleName([this, root, bleImpl](bool success, QString, QByteArray data) + bleImpl->getBleName([this, root](bool success, QString, QByteArray data) { if (!WSServer::Instance()->checkClientExists(this)) return;