Skip to content

Commit 577a451

Browse files
committed
nimble/audio: Bound broadcast sink subgroup count
Reject sync requests whose subgroup count exceeds the broadcast sink subgroup array before copying BIS sync values into it. The previous code relied on a debug assertion in the scan delegator path, but production builds can still receive an oversized sync option. Fixes #2188
1 parent 8ff6928 commit 577a451

4 files changed

Lines changed: 56 additions & 2 deletions

File tree

nimble/host/audio/src/ble_audio_broadcast_sink.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,13 +1579,23 @@ ble_audio_broadcast_sink_config(uint8_t source_id, uint16_t conn_handle,
15791579
const struct ble_audio_scan_delegator_sync_opt *sync_opt)
15801580
{
15811581
struct ble_audio_broadcast_sink *sink;
1582+
bool sync_requested;
15821583
int rc;
15831584

15841585
BLE_AUDIO_DBG_ASSERT(sync_opt != NULL);
15851586

1587+
sync_requested =
1588+
sync_opt->pa_sync != BLE_AUDIO_SCAN_DELEGATOR_PA_SYNC_DO_NOT_SYNC;
1589+
if (sync_requested &&
1590+
sync_opt->num_subgroups >
1591+
MYNEWT_VAL(BLE_AUDIO_SCAN_DELEGATOR_SUBGROUP_MAX)) {
1592+
BLE_HS_LOG_ERROR("num_subgroups above the limit\n");
1593+
return BLE_HS_EINVAL;
1594+
}
1595+
15861596
sink = broadcast_sink_get(source_id);
15871597
if (sink == NULL) {
1588-
if (sync_opt->pa_sync != BLE_AUDIO_SCAN_DELEGATOR_PA_SYNC_DO_NOT_SYNC) {
1598+
if (sync_requested) {
15891599
sink = broadcast_sink_new(source_id);
15901600
if (sink == NULL) {
15911601
return BLE_HS_ENOMEM;
@@ -1596,7 +1606,7 @@ ble_audio_broadcast_sink_config(uint8_t source_id, uint16_t conn_handle,
15961606
}
15971607
}
15981608

1599-
if (sync_opt->pa_sync != BLE_AUDIO_SCAN_DELEGATOR_PA_SYNC_DO_NOT_SYNC) {
1609+
if (sync_requested) {
16001610
/* TODO: Skip if the BIS Sync is same */
16011611
if (sink->num_subgroups != 0) {
16021612
rc = big_sync_term(sink);

nimble/host/audio/test/src/ble_audio_test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
TEST_SUITE_DECL(ble_audio_base_parse_test_suite);
2424
TEST_CASE_DECL(ble_audio_listener_register_test);
25+
TEST_CASE_DECL(ble_audio_broadcast_sink_config_test_subgroups_bound);
2526

2627
TEST_SUITE(ble_audio_test)
2728
{
2829
ble_audio_base_parse_test_suite();
2930
ble_audio_listener_register_test();
31+
ble_audio_broadcast_sink_config_test_subgroups_bound();
3032
}
3133

3234
int
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include "testutil/testutil.h"
21+
22+
#include "host/ble_hs.h"
23+
#include "audio/ble_audio_scan_delegator.h"
24+
#include "../../../src/ble_audio_broadcast_sink_priv.h"
25+
26+
TEST_CASE_SELF(ble_audio_broadcast_sink_config_test_subgroups_bound)
27+
{
28+
struct ble_audio_scan_delegator_sync_opt sync_opt = {0};
29+
int rc;
30+
31+
sync_opt.pa_sync = BLE_AUDIO_SCAN_DELEGATOR_PA_SYNC_PAST_NOT_AVAILABLE;
32+
sync_opt.num_subgroups = BLE_AUDIO_SCAN_DELEGATOR_SUBGROUP_MAX + 1;
33+
34+
rc = ble_audio_broadcast_sink_config(0, BLE_HS_CONN_HANDLE_NONE,
35+
&sync_opt);
36+
37+
TEST_ASSERT(rc == BLE_HS_EINVAL);
38+
}

nimble/host/audio/test/syscfg.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ syscfg.vals:
2929
BLE_HS_DEBUG: 1
3030

3131
BLE_EXT_ADV: 1
32+
33+
BLE_ISO_BROADCAST_SINK: 1
34+
BLE_AUDIO_BROADCAST_SINK: 1
35+
BLE_AUDIO_BROADCAST_SINK_MAX: 1

0 commit comments

Comments
 (0)