Skip to content

Commit

Permalink
Bluetooth: host: Fix CCC cfg not cleared when overwriting oldest bond
Browse files Browse the repository at this point in the history
Fix CCC cfg not cleared when overwriting oldest bond. Calling
bt_unpair with a pointer to the key will result in the key addr being
memset to zero and bt_gatt_clear is called with an zero-set address.
This happens because unpair (hci_core.c) calls bt_keys_clear before
calling bt_gatt_clear.

Signed-off-by: Joakim Andersson <[email protected]>
  • Loading branch information
joerchan authored and jhedberg committed May 12, 2020
1 parent 9a37154 commit 6de4294
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion subsys/bluetooth/host/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct bt_keys *bt_keys_get_addr(u8_t id, const bt_addr_le_t *addr)
#if IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST)
if (first_free_slot == ARRAY_SIZE(key_pool)) {
struct bt_keys *oldest = &key_pool[0];
bt_addr_le_t oldest_addr;

for (i = 1; i < ARRAY_SIZE(key_pool); i++) {
struct bt_keys *current = &key_pool[i];
Expand All @@ -71,7 +72,9 @@ struct bt_keys *bt_keys_get_addr(u8_t id, const bt_addr_le_t *addr)
}
}

bt_unpair(oldest->id, &oldest->addr);
/* Use a copy as bt_unpair will clear the oldest key. */
bt_addr_le_copy(&oldest_addr, &oldest->addr);
bt_unpair(oldest->id, &oldest_addr);
if (!bt_addr_le_cmp(&oldest->addr, BT_ADDR_LE_ANY)) {
first_free_slot = oldest - &key_pool[0];
}
Expand Down

0 comments on commit 6de4294

Please sign in to comment.