diff --git a/src/Common.cpp b/src/Common.cpp index 5b03e1e9..cdaf0133 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -514,3 +514,12 @@ QString Common::getMcAgent() } return ""; } + +QByteArray Common::getUntilNullByte(const QByteArray &arr) +{ + if (arr.contains(ZERO_BYTE)) + { + return arr.left(arr.indexOf(ZERO_BYTE)); + } + return arr; +} diff --git a/src/Common.h b/src/Common.h index cccbdc44..7679a7d3 100644 --- a/src/Common.h +++ b/src/Common.h @@ -264,6 +264,8 @@ class Common static QString getMcAgent(); + static QByteArray getUntilNullByte(const QByteArray& arr); + typedef enum { MP_Classic = 0, @@ -352,6 +354,7 @@ class Common static const int BLE_LATEST_BUNDLE_VERSION = 7; static const int BLE_BUNDLE_WITH_NOTES = 1; static const int BLE_BUNDLE_WITH_BLE_NAME = 9; + static const char ZERO_BYTE = static_cast(0x00); }; struct FidoCredential diff --git a/src/MPDeviceBleImpl.cpp b/src/MPDeviceBleImpl.cpp index 3c8e90b1..42e3756e 100644 --- a/src/MPDeviceBleImpl.cpp +++ b/src/MPDeviceBleImpl.cpp @@ -1913,11 +1913,7 @@ void MPDeviceBleImpl::getBleName(const MessageHandlerCbData &cb) bleNameArr = DEFAULT_BLE_NAME.toUtf8(); qWarning() << "Invalid character in BLE name"; } - if (bleNameArr.contains(ZERO_BYTE)) - { - // Cut zero bytes from the end of the array - bleNameArr = bleNameArr.left(bleNameArr.indexOf(ZERO_BYTE)); - } + bleNameArr = Common::getUntilNullByte(bleNameArr); cb(true, "", bleNameArr); });