Skip to content

Commit

Permalink
tests: Bluetooth: Tester: Fix use of uninitialized cig_id for CAP
Browse files Browse the repository at this point in the history
The CAP tests used u_group->cig->index but the u_group->cig may
have been deleted when the stream is released, which meant
that u_group->cig == NULL when e.g. unicast_stop_complete_cb
was called and that could cause failing tests as the index
would just be a uninitialized value.

Signed-off-by: Emil Gydesen <[email protected]>
  • Loading branch information
Thalley authored and mmahadevan108 committed Oct 31, 2024
1 parent 74a5599 commit 5ebe119
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions tests/bluetooth/tester/src/audio/btp_bap_unicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,7 @@ int btp_bap_unicast_group_create(uint8_t cig_id,
}

cigs[cig_id].in_use = true;
cigs[cig_id].cig_id = cig_id;
*out_unicast_group = &cigs[cig_id];

return 0;
Expand Down
4 changes: 4 additions & 0 deletions tests/bluetooth/tester/src/audio/btp_bap_unicast.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

/*
* Copyright (c) 2023 Codecoup
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdint.h>

#include <zephyr/bluetooth/audio/cap.h>

#define BTP_BAP_UNICAST_MAX_SNK_STREAMS_COUNT MIN(CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT, \
Expand All @@ -20,6 +23,7 @@
struct btp_bap_unicast_group {
struct bt_bap_qos_cfg qos[CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT];
struct bt_bap_unicast_group *cig;
uint8_t cig_id;
bool in_use;
};

Expand Down
8 changes: 4 additions & 4 deletions tests/bluetooth/tester/src/audio/btp_cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ static void unicast_start_complete_cb(int err, struct bt_conn *conn)

if (err != 0) {
LOG_DBG("Failed to unicast-start, err %d", err);
btp_send_cap_unicast_start_completed_ev(u_group->cig->index,
btp_send_cap_unicast_start_completed_ev(u_group->cig_id,
BTP_CAP_UNICAST_START_STATUS_FAILED);

return;
}

btp_send_cap_unicast_start_completed_ev(u_group->cig->index,
btp_send_cap_unicast_start_completed_ev(u_group->cig_id,
BTP_CAP_UNICAST_START_STATUS_SUCCESS);
}

Expand All @@ -129,13 +129,13 @@ static void unicast_stop_complete_cb(int err, struct bt_conn *conn)

if (err != 0) {
LOG_DBG("Failed to unicast-stop, err %d", err);
btp_send_cap_unicast_stop_completed_ev(u_group->cig->index,
btp_send_cap_unicast_stop_completed_ev(u_group->cig_id,
BTP_CAP_UNICAST_START_STATUS_FAILED);

return;
}

btp_send_cap_unicast_stop_completed_ev(u_group->cig->index,
btp_send_cap_unicast_stop_completed_ev(u_group->cig_id,
BTP_CAP_UNICAST_START_STATUS_SUCCESS);
}

Expand Down

0 comments on commit 5ebe119

Please sign in to comment.