Skip to content
Permalink
Browse files

Bluetooth: host: Fix bt_keys_get_addr()

Change fixes issue causing multiple keys creation for given address
and identity.

Fixes: #16478

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
  • Loading branch information...
MarekPieta authored and carlescufi committed May 29, 2019
1 parent f032729 commit c8be3e81d3ab29125c2bcd3e03639133028d18b2
Showing with 11 additions and 5 deletions.
  1. +11 −5 subsys/bluetooth/host/keys.c
@@ -35,6 +35,7 @@ struct bt_keys *bt_keys_get_addr(u8_t id, const bt_addr_le_t *addr)
{
struct bt_keys *keys;
int i;
size_t first_free_slot = ARRAY_SIZE(key_pool);

BT_DBG("%s", bt_addr_le_str(addr));

@@ -45,14 +46,19 @@ struct bt_keys *bt_keys_get_addr(u8_t id, const bt_addr_le_t *addr)
return keys;
}

if (!bt_addr_le_cmp(&keys->addr, BT_ADDR_LE_ANY)) {
keys->id = id;
bt_addr_le_copy(&keys->addr, addr);
BT_DBG("created %p for %s", keys, bt_addr_le_str(addr));
return keys;
if (first_free_slot == ARRAY_SIZE(key_pool) &&
!bt_addr_le_cmp(&keys->addr, BT_ADDR_LE_ANY)) {
first_free_slot = i;
}
}

if (first_free_slot < ARRAY_SIZE(key_pool)) {
keys = &key_pool[first_free_slot];
keys->id = id;
bt_addr_le_copy(&keys->addr, addr);
BT_DBG("created %p for %s", keys, bt_addr_le_str(addr));
return keys;
}
BT_DBG("unable to create keys for %s", bt_addr_le_str(addr));

return NULL;

0 comments on commit c8be3e8

Please sign in to comment.
You can’t perform that action at this time.