Skip to content

Commit 42c8732

Browse files
Yagoorcarlescufi
authored andcommitted
Bluetooth: Gatt: Make CCC_STORE_MAX configurable
- Made CCC_STORE_MAX configurable under the BT_SETTINGS - Added a buffer overflow check on ccc_save Fixes: #76838 Signed-off-by: Yago Fontoura do Rosario <[email protected]>
1 parent b8bef42 commit 42c8732

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

subsys/bluetooth/host/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,15 @@ config BT_SETTINGS_USE_PRINTK
238238
When not selected, Bluetooth settings will use a faster builtin
239239
function to encode the key string. The drawback is that if
240240
printk is enabled then the program memory footprint will be larger.
241+
242+
config BT_SETTINGS_CCC_STORE_MAX
243+
int "Max number of Client Characteristic Configuration (CCC)"
244+
default 48
245+
range 1 96
246+
help
247+
Defines the max number of Client Characteristic Configuration (CCC)
248+
that the stack can handle
249+
241250
endif # BT_SETTINGS
242251

243252
config BT_FILTER_ACCEPT_LIST

subsys/bluetooth/host/gatt.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5677,7 +5677,11 @@ static struct bt_gatt_exchange_params gatt_exchange_params = {
56775677
#endif /* CONFIG_BT_GATT_AUTO_UPDATE_MTU */
56785678
#endif /* CONFIG_BT_GATT_CLIENT */
56795679

5680-
#define CCC_STORE_MAX 48
5680+
#if defined(CONFIG_BT_SETTINGS_CCC_STORE_MAX)
5681+
#define CCC_STORE_MAX CONFIG_BT_SETTINGS_CCC_STORE_MAX
5682+
#else /* defined(CONFIG_BT_SETTINGS_CCC_STORE_MAX) */
5683+
#define CCC_STORE_MAX 0
5684+
#endif /* defined(CONFIG_BT_SETTINGS_CCC_STORE_MAX) */
56815685

56825686
static struct bt_gatt_ccc_cfg *ccc_find_cfg(struct _bt_gatt_ccc *ccc,
56835687
const bt_addr_le_t *addr,
@@ -6077,6 +6081,12 @@ static uint8_t ccc_save(const struct bt_gatt_attr *attr, uint16_t handle,
60776081

60786082
LOG_DBG("Storing CCCs handle 0x%04x value 0x%04x", handle, cfg->value);
60796083

6084+
CHECKIF(save->count >= CCC_STORE_MAX) {
6085+
LOG_ERR("Too many Client Characteristic Configuration. "
6086+
"See CONFIG_BT_SETTINGS_CCC_STORE_MAX\n");
6087+
return BT_GATT_ITER_STOP;
6088+
}
6089+
60806090
save->store[save->count].handle = handle;
60816091
save->store[save->count].value = cfg->value;
60826092
save->count++;

0 commit comments

Comments
 (0)