Skip to content

Commit 2ab42db

Browse files
Thalleycarlescufi
authored andcommitted
Bluetooth: Audio: Fix broadcast sink LTV decode length issue
The broadcast sink did not properly decode the LTV data from the BASE. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 6656607 commit 2ab42db

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

subsys/bluetooth/audio/broadcast_sink.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ static void pa_term(struct bt_le_per_adv_sync *sync,
264264
static bool net_buf_decode_codec_ltv(struct net_buf_simple *buf,
265265
struct bt_codec_data *codec_data)
266266
{
267-
size_t value_len;
268267
void *value;
269268

270269
if (buf->len < sizeof(codec_data->data.data_len)) {
@@ -277,17 +276,22 @@ static bool net_buf_decode_codec_ltv(struct net_buf_simple *buf,
277276
BT_DBG("Not enough data for LTV type field: %u", buf->len);
278277
return false;
279278
}
279+
280+
/* LTV structures include the data.type in the length field,
281+
* but we do not do that for the bt_data struct in Zephyr
282+
*/
283+
codec_data->data.data_len -= sizeof(codec_data->data.type);
284+
280285
codec_data->data.type = net_buf_simple_pull_u8(buf);
281286
codec_data->data.data = codec_data->value;
282287

283-
value_len = codec_data->data.data_len - sizeof(codec_data->data.type);
284-
if (buf->len < value_len) {
288+
if (buf->len < codec_data->data.data_len) {
285289
BT_DBG("Not enough data for LTV value field: %u/%zu",
286-
buf->len, value_len);
290+
buf->len, codec_data->data.data_len);
287291
return false;
288292
}
289-
value = net_buf_simple_pull_mem(buf, value_len);
290-
memcpy(codec_data->value, value, value_len);
293+
value = net_buf_simple_pull_mem(buf, codec_data->data.data_len);
294+
(void)memcpy(codec_data->value, value, codec_data->data.data_len);
291295

292296
return true;
293297
}

0 commit comments

Comments
 (0)