diff options
author | Jean-François Milants <jf@codingfield.com> | 2022-03-14 20:44:19 +0100 |
---|---|---|
committer | JF <JF002@users.noreply.github.com> | 2022-03-21 20:53:15 +0100 |
commit | df61907073fab7d4c2f9595c7771e894a3841b65 (patch) | |
tree | 9a3b45b688dd15c32016d4e3e90ec09a0d3a9be5 /src/components | |
parent | 1c4a56b05bf4fcd89d95a7c04e5a7a22f554f00c (diff) |
Limit the size of the track and album name received by MusicService. This should work around this bug : https://github.com/InfiniTimeOrg/InfiniTime/issues/825 and prevent heap over-allocation.
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/ble/MusicService.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/components/ble/MusicService.cpp b/src/components/ble/MusicService.cpp index 3457ce4c..7b74ac2e 100644 --- a/src/components/ble/MusicService.cpp +++ b/src/components/ble/MusicService.cpp @@ -47,6 +47,8 @@ namespace { constexpr ble_uuid128_t msRepeatCharUuid {CharUuid(0x0b, 0x00)}; constexpr ble_uuid128_t msShuffleCharUuid {CharUuid(0x0c, 0x00)}; + constexpr uint8_t MaxStringSize {40}; + int MusicCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { return static_cast<Pinetime::Controllers::MusicService*>(arg)->OnCommand(conn_handle, attr_handle, ctxt); } @@ -125,6 +127,11 @@ void Pinetime::Controllers::MusicService::Init() { int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt) { if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) { size_t notifSize = OS_MBUF_PKTLEN(ctxt->om); + + if(notifSize > MaxStringSize) { + notifSize = MaxStringSize; + } + char data[notifSize + 1]; data[notifSize] = '\0'; os_mbuf_copydata(ctxt->om, 0, notifSize, data); |