Skip to content

Commit a1471dd

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 Signed-off-by: Old-Ding <ai.neo.ae86@gmail.com>
1 parent 8ff6928 commit a1471dd

4 files changed

Lines changed: 54 additions & 2 deletions

File tree

nimble/host/audio/src/ble_audio_broadcast_sink.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,13 +1579,21 @@ 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 = sync_opt->pa_sync != BLE_AUDIO_SCAN_DELEGATOR_PA_SYNC_DO_NOT_SYNC;
1588+
if (sync_requested && sync_opt->num_subgroups >
1589+
MYNEWT_VAL(BLE_AUDIO_SCAN_DELEGATOR_SUBGROUP_MAX)) {
1590+
BLE_HS_LOG_ERROR("num_subgroups above the limit\n");
1591+
return BLE_HS_EINVAL;
1592+
}
1593+
15861594
sink = broadcast_sink_get(source_id);
15871595
if (sink == NULL) {
1588-
if (sync_opt->pa_sync != BLE_AUDIO_SCAN_DELEGATOR_PA_SYNC_DO_NOT_SYNC) {
1596+
if (sync_requested) {
15891597
sink = broadcast_sink_new(source_id);
15901598
if (sink == NULL) {
15911599
return BLE_HS_ENOMEM;
@@ -1596,7 +1604,7 @@ ble_audio_broadcast_sink_config(uint8_t source_id, uint16_t conn_handle,
15961604
}
15971605
}
15981606

1599-
if (sync_opt->pa_sync != BLE_AUDIO_SCAN_DELEGATOR_PA_SYNC_DO_NOT_SYNC) {
1607+
if (sync_requested) {
16001608
/* TODO: Skip if the BIS Sync is same */
16011609
if (sink->num_subgroups != 0) {
16021610
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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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, &sync_opt);
35+
36+
TEST_ASSERT(rc == BLE_HS_EINVAL);
37+
}

nimble/host/audio/test/syscfg.yml

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

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

0 commit comments

Comments
 (0)