Skip to content

Commit df61907

Browse files
committed
Limit the size of the track and album name received by MusicService. This should work around this bug : #825 and prevent heap over-allocation.
1 parent 1c4a56b commit df61907

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/components/ble/MusicService.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ namespace {
4747
constexpr ble_uuid128_t msRepeatCharUuid {CharUuid(0x0b, 0x00)};
4848
constexpr ble_uuid128_t msShuffleCharUuid {CharUuid(0x0c, 0x00)};
4949

50+
constexpr uint8_t MaxStringSize {40};
51+
5052
int MusicCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
5153
return static_cast<Pinetime::Controllers::MusicService*>(arg)->OnCommand(conn_handle, attr_handle, ctxt);
5254
}
@@ -125,6 +127,11 @@ void Pinetime::Controllers::MusicService::Init() {
125127
int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt) {
126128
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
127129
size_t notifSize = OS_MBUF_PKTLEN(ctxt->om);
130+
131+
if(notifSize > MaxStringSize) {
132+
notifSize = MaxStringSize;
133+
}
134+
128135
char data[notifSize + 1];
129136
data[notifSize] = '\0';
130137
os_mbuf_copydata(ctxt->om, 0, notifSize, data);

0 commit comments

Comments
 (0)