Skip to content

Commit 220571e

Browse files
Thalleycfriedt
authored andcommitted
Bluetooth: CCP: Check conn type before access by index
Ensure that the connection type of the provided bt_conn is an LE connection. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 0347d92 commit 220571e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

subsys/bluetooth/audio/ccp_call_control_client.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ static struct bt_ccp_call_control_client clients[CONFIG_BT_MAX_CONN];
5555

5656
static struct bt_ccp_call_control_client *get_client_by_conn(const struct bt_conn *conn)
5757
{
58+
__ASSERT(bt_conn_is_type(conn, BT_CONN_TYPE_LE), "Invalid connection type for %p", conn);
59+
5860
return &clients[bt_conn_index(conn)];
5961
}
6062

@@ -176,6 +178,11 @@ int bt_ccp_call_control_client_discover(struct bt_conn *conn,
176178
return -EINVAL;
177179
}
178180

181+
if (!bt_conn_is_type(conn, BT_CONN_TYPE_LE)) {
182+
LOG_DBG("Invalid connection type for %p", conn);
183+
return -EINVAL;
184+
}
185+
179186
client = get_client_by_conn(conn);
180187
if (atomic_test_and_set_bit(client->flags, CCP_CALL_CONTROL_CLIENT_FLAG_BUSY)) {
181188
return -EBUSY;

tests/bluetooth/audio/mocks/src/conn.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <stdint.h>
88

99
#include <errno.h>
10+
#include <stdbool.h>
1011
#include <stddef.h>
1112
#include <stdint.h>
1213

@@ -76,3 +77,8 @@ void mock_bt_conn_disconnected(struct bt_conn *conn, uint8_t err)
7677
}
7778
}
7879
}
80+
81+
bool bt_conn_is_type(const struct bt_conn *conn, enum bt_conn_type type)
82+
{
83+
return true;
84+
}

0 commit comments

Comments
 (0)